473,880 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using declarations with nested typedefs

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
4 2703

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

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

"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:678Ab.3390 3$_M.147470@att bi_s54...
"Dave" <be***********@ yahoo.com> wrote...

"Dave" <be***********@ yahoo.com> wrote in message
news:vt******** ****@news.super news.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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4316
by: Sergio Otoya | last post by:
Hi all, I need to add an input hidden field to an existing form (post). I have tried a couple things like adding the '<INPUT type=hidden name=idSelectedURL value=http://server/documents>' to the innerHTML of the form but it fails. ie
1
1380
by: Robert J. Hansen | last post by:
I'm exploring the use of type traits (which, I hasten to say, I've hardly ever used before) as a way to help simplify some complex special-case logic in an existing codebase. I'm finding that I'm running into some of the sharp corners of the C++ template facility. I'm hoping someone can answer a couple of questions about the following code snippet: ===== template <
3
4504
by: pyramus | last post by:
I am wondering which one should be preferred for creating a local synonym within a function definition. Let's say I have a type in my library called MyLib::Foundation::int32, which I can't stand typing all the time. Should I do: void foo() { typedef MyLib::Foundation::int32 int32; int32 x = 0; }
30
6114
by: junky_fellow | last post by:
I was looking at the source code of linux or open BSD. What I found that lots of typedefs were used. For example, consider the offset in a file. It was declared as off_t offset; and off_t is typedefed as typedef long off_t; I wanted to know what advantage do we get by typedefs ? Why we did not declare
2
508
by: Carlos Martinez Garcia | last post by:
Hi all: I usually make forward declarations in headers. Something like this: class MyClass; Now, I need a reference to a type defined like this (traditional C Style): typedef struct {
7
6002
by: Noah Roberts | last post by:
I have something like the following: template<ENUM X, int I = 0> class Generic { .... }; typedef Generic<Val1> v1_type; typedef Generic<Val2> v2_type;
28
1996
by: Tom Plunket | last post by:
Hey gang; In C++ I often used forward declarations to allow me to get away with not including additional files in headers, if in fact all I needed was to know that a type existed. e.g. foo.h: struct Bar;
3
11565
by: steve | last post by:
Hi all, I want to be able to hirearchally define event delegate (declarations) WITHIN interfaces. Unfortunatelly C# 1 doesn't appear to support it. How does the following look as a work-around? Are there better ways of doing this?
1
1767
by: borophyll | last post by:
The C standard talks about nested declarators, and th only example of nested declarators I can think of are function parameter declarations, which are nested within the function declaration. Are there any other examples of nested declarations? regards, B.
0
9925
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9772
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10713
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10809
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7948
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5777
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5972
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4595
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.