Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Templates and forward declarations

Templates and forward declarations

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++wpf
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jonas Petterssn
    wrote on last edited by
    #1

    As we all know, forward declarations are necesary to implement circular references, like below: struct A; struct B { A * a; }; struct A { B * b }; My problem is, how do i deal with this using templates? The following pice of code is a syntax error in VC++ 6.0: template struct A; template struct B { A * a; }; template struct A { B * b }; Does anyone know th correct syntax? :confused: Jonas Pettersson

    J 1 Reply Last reply
    0
    • J Jonas Petterssn

      As we all know, forward declarations are necesary to implement circular references, like below: struct A; struct B { A * a; }; struct A { B * b }; My problem is, how do i deal with this using templates? The following pice of code is a syntax error in VC++ 6.0: template struct A; template struct B { A * a; }; template struct A { B * b }; Does anyone know th correct syntax? :confused: Jonas Pettersson

      J Offline
      J Offline
      Jonas Petterssn
      wrote on last edited by
      #2

      Hmm, this discussion group does not seem to support brackets, they didn't get posted. I'll re-write the question using parenthesis as brackets... ------------------------------------------------------------------------------------------ As we all know, forward declarations are necesary to implement circular references, like below: struct A; struct B { A * a; }; struct A { B * b }; My problem is, how do i deal with this using templates? The following pice of code is a syntax error in VC++ 6.0: template(class C) struct A; template(class C) struct B { A(C) * a; }; template(class C) struct A { B(C) * b }; Jonas

      W 1 Reply Last reply
      0
      • J Jonas Petterssn

        Hmm, this discussion group does not seem to support brackets, they didn't get posted. I'll re-write the question using parenthesis as brackets... ------------------------------------------------------------------------------------------ As we all know, forward declarations are necesary to implement circular references, like below: struct A; struct B { A * a; }; struct A { B * b }; My problem is, how do i deal with this using templates? The following pice of code is a syntax error in VC++ 6.0: template(class C) struct A; template(class C) struct B { A(C) * a; }; template(class C) struct A { B(C) * b }; Jonas

        W Offline
        W Offline
        Walter Gildersleeve
        wrote on last edited by
        #3

        I don't get template-related syntax errors when compiling the code in VC6 after simply changing the parentheses to brackets...there is a missing semi-colon after B* b in struct A, but other than that, no problems. (I'm able to create instances of the structs, too; link and running is no problem.) Walter Gildersleeve Freiburg, Germany walter.gildersleeve@pe-gmbh.de

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups