using declarations with nested typedefs

D

Dave

Is the using declaration shown in the program below valid? My compiler
accepts it, but I'm not sure if it should...

class foo_t
{
public:
typedef int X;
};

int main()
{
using foo_t::x;
X a;
}
 
D

Dave

Dave said:
Is the using declaration shown in the program below valid? My compiler
accepts it, but I'm not sure if it should...

class foo_t
{
public:
typedef int X;
};

int main()
{
using foo_t::x;
X a;
}
Sorry, it should've been: using foo_t::X;

I typed in the example by hand...
 
V

Victor Bazarov

Dave said:
Sorry, it should've been: using foo_t::X;

Answering your original question, yes, it's valid. 'X' is a synonym
for 'int' in 'foo_t' declarative region. You may bring that name
into any other declarative region, where foo_t::X is accessible.

I guess since your compiler accepts it, you don't have a problem,
but may I ask, what prompted your question in the first place?

Victor
 
D

Dave

Victor Bazarov said:
Answering your original question, yes, it's valid. 'X' is a synonym
for 'int' in 'foo_t' declarative region. You may bring that name
into any other declarative region, where foo_t::X is accessible.

I guess since your compiler accepts it, you don't have a problem,
but may I ask, what prompted your question in the first place?

Victor

Well, my compiler (VC++ 7.1) accepts it, but Comeau (the online test-drive
version) does not...

Comeau (as well as my compiler) will, however, accept this:

typedef foo_t::X X;

You know, looking at the C++ grammar as defined in the Standard, it appears
that, syntactically, a using declaration may indeed be used to access a
class scope. Of course, this jives with your statement that it is valid.
Unless there's a semantic reason this is invalid that we've both missed,
perhaps a minor bug has just been found in Comeau??????

I'd love to hear your further thoughts as well as any other thoughts anyone
has...
 
A

Andrey Tarasevich

Dave said:
Is the using declaration shown in the program below valid? My compiler
accepts it, but I'm not sure if it should...

class foo_t
{
public:
typedef int X;
};

int main()
{
using foo_t::x;
X a;
}

No, it is not valid. 7.3.3/6 states that a using declaration for a class
member shall be a member declaration. Nested 'typedef's are class
members, according to 9.2/1.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top