forward declaration with namespace

T

Torsten Mueller

I have sources containing lots of namespaces (even nested ...)

I'm porting these classes to gcc 3.3.2. At the moment I get several
error messages like this:

../../src/libFormalValidation/ErrorCache.h:20:
error: forward declaration of `struct Support::CErrorInfo'

The code at this place is:

namespace Support
{
class CErrorInfo; // <- here
}

This is a forward declaration of a class located in a namespace. This
class name will be used later for pointers, references and template
parameters. This is legal on MSVC and on HPUX aCC. Is this illegal on
gcc?

T.M.
 
N

nymano

your forward declaration declares CErrorInfo as a class. however, the
error message referes to CErrorInfo as a struct. is it a class or a
struct?

stoyan.
 
T

Torsten Mueller

nymano said:
your forward declaration declares CErrorInfo as a class. however, the
error message referes to CErrorInfo as a struct. is it a class or a
struct?

"class" is a special case of "struct". gcc uses the more common word
"struct" in it's error messages which means both classes and structs.

My code contains the following definition:

namespace Support {
class CErrorInfo
{
// ...
};
}

My guess is: classes declared forward are not usable as template
parameter type later. But I can't imagine this really.

T.M.
 
M

Marc Mutz

Torsten Mueller wrote:
My guess is: classes declared forward are not usable as
template parameter type later. But I can't imagine this
really.
<snip>

Whether or not a template instantiation needs the type
definition depends on the template. E.g.
std::tr1::smart_ptr<T> doesn't need T's full type to
instantiate any member function (AFAIR, except when you
use the default value of the 2nd ctor argument - the
deleter).
std::pair<U,V> need the full type, though.

The forward declaration you have posted is completely ok.
The problem lies elsewhere. Post more code, and an error
message.

Marc
 

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,797
Messages
2,569,647
Members
45,378
Latest member
danzeev

Latest Threads

Top