use of undefined types

S

Steffen Hampel

class Cfoo {

class Innerfoo;

typedef Innerfoo::Type1 Type1; // error: use of undefined type

Cfoo::Innerfoo::Type1 bar; // error: use of undefined type
};

class Cfoo::Innerfoo {

typedef int Type1;
};

My understanding of the standard was that you can use undefined types in
declarations. The GCC agrees (no errors) but the VC++ compiler doesn't
(error messages as above). Who is right? I want to write compiler
independ code dammit.
 
F

Fei Liu

Steffen said:
class Cfoo {

class Innerfoo;

typedef Innerfoo::Type1 Type1; // error: use of undefined type

Cfoo::Innerfoo::Type1 bar; // error: use of undefined type
};

class Cfoo::Innerfoo {

typedef int Type1;
};

My understanding of the standard was that you can use undefined types in
declarations. The GCC agrees (no errors) but the VC++ compiler doesn't
(error messages as above). Who is right? I want to write compiler
independ code dammit.
Try this:

class Cfoo {

class Innerfoo{
typedef int Type1;
};

typedef Innerfoo::Type1 Type1; // error: use of undefined type

Cfoo::Innerfoo::Type1 bar; // error: use of undefined type
};
 
J

James Kanze

class Cfoo {
class Innerfoo;
typedef Innerfoo::Type1 Type1; // error: use of undefined type
Cfoo::Innerfoo::Type1 bar; // error: use of undefined type
};
class Cfoo::Innerfoo {
typedef int Type1;
};
My understanding of the standard was that you can use
undefined types in declarations.

You can never use an undeclared symbol, period. There are
certain contexts where you can use an incomplete type, but the
symbol naming the type must be in scope. (In the first case
above, an incomplete type would be acceptable; in the second
no.)
The GCC agrees (no errors) but the VC++ compiler doesn't
(error messages as above).

The code is definitely wrong, and I get an error from both g++
and Sun CC.
 

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

Forum statistics

Threads
474,173
Messages
2,570,937
Members
47,481
Latest member
ElviraDoug

Latest Threads

Top