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. namespaces

namespaces

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 Posts 3 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.
  • S Offline
    S Offline
    scratchmonkey
    wrote on last edited by
    #1

    filename: cat.h #include "dog.h" namespace Mammal { namespace Dog { class Collie { void virtual init( Mammal::Cat::Siamese *siamese ); } } } filename: dog.h #include "cat.h" namespace Mammal { namespace Cat { class Siamese { Mammal::Dog::Collie *collie; ... } } } If I try to compile this, I get an error that says "Siamese is not a member of Mammal::Cat Any ideas why?

    L 1 Reply Last reply
    0
    • S scratchmonkey

      filename: cat.h #include "dog.h" namespace Mammal { namespace Dog { class Collie { void virtual init( Mammal::Cat::Siamese *siamese ); } } } filename: dog.h #include "cat.h" namespace Mammal { namespace Cat { class Siamese { Mammal::Dog::Collie *collie; ... } } } If I try to compile this, I get an error that says "Siamese is not a member of Mammal::Cat Any ideas why?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      1. You have the two classes (Siamese and Collie) dependant on each other which even if it works is poor practice. 2. Siamese has no functions defined. Elaine :rose: The tigress is here :-D

      S 1 Reply Last reply
      0
      • L Lost User

        1. You have the two classes (Siamese and Collie) dependant on each other which even if it works is poor practice. 2. Siamese has no functions defined. Elaine :rose: The tigress is here :-D

        S Offline
        S Offline
        scratchmonkey
        wrote on last edited by
        #3

        I know it's a circular dependancy, and I promise I'll do penance for that. But that wouldn't account for the compiler not finding Siamese in the Mammal::Cat namespace. And there is more to each class, but these are the lines that I've narrowed down as the most likely candidates for causing the problem. As far as I can tell, the namespaces are set up properly, and Visual Studio has no problem parsing them to generate the class view or to generate the drop-down list for the auto-complete feature, but the compiler won't compile it, claiming that the Siamese class is not a member of that namespace.

        A 1 Reply Last reply
        0
        • S scratchmonkey

          I know it's a circular dependancy, and I promise I'll do penance for that. But that wouldn't account for the compiler not finding Siamese in the Mammal::Cat namespace. And there is more to each class, but these are the lines that I've narrowed down as the most likely candidates for causing the problem. As far as I can tell, the namespaces are set up properly, and Visual Studio has no problem parsing them to generate the class view or to generate the drop-down list for the auto-complete feature, but the compiler won't compile it, claiming that the Siamese class is not a member of that namespace.

          A Offline
          A Offline
          Anthony_Yio
          wrote on last edited by
          #4

          May be you could try forward declaration. like namespace Mammal { namespace Cat{ Class Siamese;} } then, the actual dog namespace then, the actual cat namespace. Sonork 100.41263:Anthony_Yio

          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