namespace is not visible in a class?

R

r.z.

I include 2 headers: the first defines some namespace A and the second
defines class B which contains some member instances of classes defined in
namespace A.

header1:

namespace A
{
class C;
};

header2:

class B
{
A::C c_instance;
};

Why does the compiler complain during compilation of header2 that A is not a
namespace?
 
C

Colander

I include 2 headers: the first defines some namespace A and the second
defines class B which contains some member instances of classes defined in
namespace A.

header1:

namespace A
{
class C;

};

header2:

class B
{
A::C c_instance;

};

Why does the compiler complain during compilation of header2 that A is not a
namespace?

My compiler says "field 'c_instance' has incomplete type" when tried.

Could you post some minimal code that shows the error?
 
R

r.z.

My compiler says "field 'c_instance' has incomplete type" when tried.

Could you post some minimal code that shows the error?

just put class C definition instead of its declaration in namespace A and it
shoul give you the same error as me
 
I

Ian Collins

r.z. said:
I include 2 headers: the first defines some namespace A and the second
defines class B which contains some member instances of classes defined in
namespace A.

header1:

namespace A
{
class C;
};

header2:

class B
{
A::C c_instance;
};

Why does the compiler complain during compilation of header2 that A is not a
namespace?
Because you haven't included header1?
 
R

r.z.

Because you haven't included header1?

it is included - I can use A::C c_instance in main.cpp but not in header2.
 
C

Colander

just put class C definition instead of its declaration in namespace A and it
shoul give you the same error as me

Nope, the next compiles fine;


namespace A
{
class C{
public:
C(){};
};
};

class B
{
A::C c;
};

int main(void)
{
B b;
return 0;
}


So, or your compiler is wrong, or there is something else that is
important to the problem in your code that you havn't posted to this
group yet....
 
R

r.z.

SOLVED.
I did forget to include header1 in header2.
I am an ass of a developer.
thanks for comments.
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top