forward declaration of class in namespace

F

flopbucket

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
 
I

Ian Collins

flopbucket said:
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;
}
 
M

Mark P

Ian said:
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>).
 

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
473,772
Messages
2,569,591
Members
45,100
Latest member
MelodeeFaj
Top