By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

Fwd declarations crossing namespaces

P: n/a
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

Aug 3 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a

<ja**********@gmail.comwrote in message
news:11*********************@57g2000hsv.googlegrou ps.com...
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;
};
}

Aug 4 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.