Anther inner class question

G

Glen Able

class Outer
{
typedef int MyInt;

class Inner
{
Outer::MyInt m_thing;
};
};

In this case, when VC sees the declaration of m_thing, it gives the error
"use of undefined type 'Outer'"

Shouldn't this compile OK? I'm assuming there's no special scoping rules
for typedefs are there?

thanks.
 
S

Sharad Kala

Glen Able said:
class Outer
{
typedef int MyInt;

class Inner
{
Outer::MyInt m_thing;
};
};

Which VC?
VC 7 doesn't complain about this code, same with Comeau online.
 
G

Glen Able

Glen Able said:
Which VC?
VC 7 doesn't complain about this code, same with Comeau online.
Sorry, that's VC6. So, I guess that code *is* valid, then. Seems like
there are quite a few scope-related bugs in VC6, no?
 
F

Frank Schmitt

Glen Able said:
Sorry, that's VC6. So, I guess that code *is* valid, then. Seems like
there are quite a few scope-related bugs in VC6, no?

Actually, it's not a scope-related bug, but an accessibility problem.
According to the standard, inner classes don't have access to private
members of the outer class (this is considered a defect in the standard,
though - see http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#45)
As a workaround, you can either make the typedef public or make Inner a
friend of Outer.

HTH & kind regards
frank
 

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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top