By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

using declarations with nested typedefs

P: n/a
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;
}
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Dave" <be***********@yahoo.com> wrote in message
news:vt************@news.supernews.com...
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...
Jul 22 '05 #2

P: n/a
"Dave" <be***********@yahoo.com> wrote...

"Dave" <be***********@yahoo.com> wrote in message
news:vt************@news.supernews.com...
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;


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
Jul 22 '05 #3

P: n/a

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:678Ab.33903$_M.147470@attbi_s54...
"Dave" <be***********@yahoo.com> wrote...

"Dave" <be***********@yahoo.com> wrote in message
news:vt************@news.supernews.com...
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;


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...
Jul 22 '05 #4

P: n/a
Dave wrote:
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.

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.