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

forward declaration of class in namespace

P: n/a
Hi,

How can I forward declare a class that is in a different namespace? As
a simple example:

classs Foo
{
std::string *string;
};
With other classes, I could always "class Y;" at the top to forward
declare, but how can I forward declare std::string? Is it possible?

I tried

class std::string;

but that did not work.

Any information appreciated.

Thansk

Jun 28 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
flopbucket wrote:
Hi,

How can I forward declare a class that is in a different namespace? As
a simple example:

classs Foo
{
std::string *string;
};
With other classes, I could always "class Y;" at the top to forward
declare, but how can I forward declare std::string? Is it possible?

I tried

class std::string;

but that did not work.

You probably can't for std:: string because it is a typedef, not a class.

If you want to forward declare a class from a namespace, use

namespace someNamespace
{
SomeClass;
}

--
Ian Collins.
Jun 28 '06 #2

P: n/a
Ian Collins wrote:
flopbucket wrote:
Hi,

How can I forward declare a class that is in a different namespace? As
a simple example:

classs Foo
{
std::string *string;
};
With other classes, I could always "class Y;" at the top to forward
declare, but how can I forward declare std::string? Is it possible?

I tried

class std::string;

but that did not work.

You probably can't for std:: string because it is a typedef, not a class.

If you want to forward declare a class from a namespace, use

namespace someNamespace
{
SomeClass;
}


That works in general, however IIRC it's not allowed to put anything in
namespace std so there's no way to forward declare names from std
(except where explicitly provided, e.g. <iosfwd>).
Jun 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.