Discussion:
forward declaration with namespace
(too old to reply)
Torsten Mueller
2005-08-26 09:46:06 UTC
Permalink
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.
nymano
2005-08-26 10:01:59 UTC
Permalink
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.
Torsten Mueller
2005-08-26 11:06:33 UTC
Permalink
Post by 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?
"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.
Marc Mutz
2005-08-26 11:34:51 UTC
Permalink
Torsten Mueller wrote:
<snip>
Post by Torsten Mueller
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

Continue reading on narkive:
Loading...