Fwd declarations crossing namespaces

J

jake77.lucas

I'm using 2005.Net C++ compiler. I have a base class in namespace A
(call it Class1). I derive another class from it, (call it Class2)
defined in namespace B. This derived class contains as a member datum
a pointer to an object of type Class3 from namespace A, and thus
requires forward declaration. I attempted the following in the Class 2
hpp file:

#include "Class1.hpp" // << Base class "A::Class1" - need this of
course.

namespace B{

// >> Fwd declare class 3 from namespace A:

class A::Class3; // << Compiler can't seem to understand this fwd
declaration??

// >> Define the derived class:

class Class2 : public A::Class1
{
// >> Member data pointer to object of type A::Class3:

A::Class3* m_obj3; // << This is why I included the fwd
declaration:
};

}

What in the world is wrong with the forward declaration?

Unfortunately the only work-around that I have found is to "#include
Class3.hpp" - which I hate to do in .hpp files.

Anyone understand this?
EWL
 
M

Matthew Crisanti

I'm using 2005.Net C++ compiler. I have a base class in namespace A
(call it Class1). I derive another class from it, (call it Class2)
defined in namespace B. This derived class contains as a member datum
a pointer to an object of type Class3 from namespace A, and thus
requires forward declaration. I attempted the following in the Class 2
hpp file:

#include "Class1.hpp" // << Base class "A::Class1" - need this of
course.

namespace B{

// >> Fwd declare class 3 from namespace A:

class A::Class3; // << Compiler can't seem to understand this fwd
declaration??

// >> Define the derived class:

class Class2 : public A::Class1
{
// >> Member data pointer to object of type A::Class3:

A::Class3* m_obj3; // << This is why I included the fwd
declaration:
};

}

What in the world is wrong with the forward declaration?

Unfortunately the only work-around that I have found is to "#include
Class3.hpp" - which I hate to do in .hpp files.

Anyone understand this?
EWL


namespace A {
class Class3; // forward declaration
}

namespace B {
class Class2 : public A::Class1
{

A::Class3* m_obj3;
};
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top