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

class namespace1::namespace2::class1;

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

class namespace1::namespace2::class1;

Jun 20 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
v4vijayakumar wrote:
Why following statement is not a "forward declaration"? :(

class namespace1::namespace2::class1;
Who knows? Try

namespace namespace1 { namespace namespace2 { class class1; } }

instead.

john
Jun 20 '07 #2

P: n/a
On Jun 20, 3:33 pm, v4vijayakumar <vijayakumar.subbu...@gmail.com>
wrote:
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/

Jun 20 '07 #3

P: n/a
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
Jun 20 '07 #4

P: n/a
On Jun 20, 4:19 pm, John Harrison <john_androni...@hotmail.comwrote:
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
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/

Jun 20 '07 #5

P: n/a
On Jun 20, 4:19 pm, John Harrison <john_androni...@hotmail.comwrote:
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
Ooops forgot the post the sample code
namespace x
{
namespace y
{

class CTest
{

};
}
}

class x::y::CTest;

This is it

Jun 20 '07 #6

P: n/a
Sarath wrote:
On Jun 20, 4:19 pm, John Harrison <john_androni...@hotmail.comwrote:
> 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

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.

--
Ian Collins.
Jun 20 '07 #7

P: n/a
On Jun 20, 5:16 pm, Ian Collins <ian-n...@hotmail.comwrote:
Sarath wrote:
On Jun 20, 4:19 pm, John Harrison <john_androni...@hotmail.comwrote:
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
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.

--
Ian Collins.
I was talking about the validity of the statement. Sorry if poorly
communicated.

Jun 20 '07 #8

P: n/a
Sarath wrote:
On Jun 20, 5:16 pm, Ian Collins <ian-n...@hotmail.comwrote:
>Sarath wrote:
>>On Jun 20, 4:19 pm, John Harrison <john_androni...@hotmail.comwrote:
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
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 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.

--
Ian Collins.
Jun 20 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.