class namespace1::namespace2::class1;

V

v4vijayakumar

Why following statement is not a "forward declaration"? :(

class namespace1::namespace2::class1;
 
J

John Harrison

v4vijayakumar said:
Why following statement is not a "forward declaration"? :(

class namespace1::namespace2::class1;

Who knows? Try

namespace namespace1 { namespace namespace2 { class class1; } }

instead.

john
 
S

Sarath

Why following statement is not a "forward declaration"? :(

class namespace1::namespace2::class1;

Hmmm... hard to guess...

In your case, I fear the compiler could not resolve the namespace as
you are not including the file (probably the .h file) which has
defined the namespace. That's why the compiler shows error. AFAIK,
namespace can't be forward declared. If the namespace declaration
available, your code will be perfectly valid.

Regards,
Sarath
http://sarathc.wordpress.com/
 
J

John Harrison

If the namespace declaration
available, your code will be perfectly valid.

namespace x
{
namespace y
{
}
}

class x::y::c;

Errors

error C2039: 'c' : is not a member of 'x::y'
error C2365: 'x' : redefinition; previous definition was 'namespace'
error C2079: 'c' uses undefined class 'x'

john
 
S

Sarath

If the namespace declaration


namespace x
{
namespace y
{
}

}

class x::y::c;

Errors

error C2039: 'c' : is not a member of 'x::y'
error C2365: 'x' : redefinition; previous definition was 'namespace'
error C2079: 'c' uses undefined class 'x'

john

In my Visual C++ 6.0 and 7.1 compiler the above statement is perfectly
valid. I'm not sure about other compilers.

Regards,
Sarath
http://sarathc.wordpress.com/
 
S

Sarath

If the namespace declaration


namespace x
{
namespace y
{
}

}

class x::y::c;

Errors

error C2039: 'c' : is not a member of 'x::y'
error C2365: 'x' : redefinition; previous definition was 'namespace'
error C2079: 'c' uses undefined class 'x'

john

Ooops forgot the post the sample code


namespace x
{
namespace y
{

class CTest
{

};
}
}

class x::y::CTest;

This is it
 
I

Ian Collins

Sarath said:
Ooops forgot the post the sample code


namespace x
{
namespace y
{

class CTest
{

};
}
}

class x::y::CTest;

This is it
This isn't a forward declaration, John's was.
 
I

Ian Collins

Sarath said:
I was talking about the validity of the statement. Sorry if poorly
communicated.
I see, but the topic was forward declarations, for which the syntax
isn't valid. One has to use the containing namespace as shown in John's
original post.

Please don't quote signatures.
 

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

No members online now.

Forum statistics

Threads
474,292
Messages
2,571,494
Members
48,179
Latest member
รับปั๊มไลค์|LikePro

Latest Threads

Top