C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How can I find back the name of my class?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
lulu yao
Guest





PostPosted: Thu Mar 17, 2005 9:40 pm    Post subject: How can I find back the name of my class? Reply with quote



Hi all,

see the following excerpt, just for test

======
int C;

class C {
....
};

....

C a; // failed to compile
======

How can I indicate compiler I want a class name rather than variable
name?

Regards


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Heinz Ozwirk
Guest





PostPosted: Fri Mar 18, 2005 1:03 pm    Post subject: Re: How can I find back the name of my class? Reply with quote



"lulu yao" <lulu.yao (AT) gmail (DOT) com> schrieb im Newsbeitrag news:1111067523.664639.118640 (AT) z14g2000cwz (DOT) googlegroups.com...
Quote:
Hi all,

see the following excerpt, just for test

======
int C;

class C {
...
};

...

C a; // failed to compile
======

How can I indicate compiler I want a class name rather than variable
name?

class C a;

HTH
Heinz

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Victor Bazarov
Guest





PostPosted: Fri Mar 18, 2005 1:05 pm    Post subject: Re: How can I find back the name of my class? Reply with quote



"lulu yao" <lulu.yao (AT) gmail (DOT) com> wrote...
Quote:
Hi all,

see the following excerpt, just for test

======
int C;

class C {
...
};

...

C a; // failed to compile
======

How can I indicate compiler I want a class name rather than variable
name?

You write

class C a;

V



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
R Samuel Klatchko
Guest





PostPosted: Fri Mar 18, 2005 1:05 pm    Post subject: Re: How can I find back the name of my class? Reply with quote

lulu yao wrote:
Quote:
======
int C;

class C {
...
};

...

C a; // failed to compile
======

How can I indicate compiler I want a class name rather than variable
name?

Qualify the class name with "class":

class C a;

samuel

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Stefan Strasser
Guest





PostPosted: Fri Mar 18, 2005 1:06 pm    Post subject: Re: How can I find back the name of my class? Reply with quote

lulu yao schrieb:

Quote:
int C;

class C {
....
};

C a; // failed to compile
======

How can I indicate compiler I want a class name rather than variable
name?

class C a;

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Raymond Martineau
Guest





PostPosted: Fri Mar 18, 2005 1:08 pm    Post subject: Re: How can I find back the name of my class? Reply with quote

On 17 Mar 2005 16:40:50 -0500, "lulu yao" <lulu.yao (AT) gmail (DOT) com> wrote:

Quote:
int C;

class C {
...
};

...

C a; // failed to compile

class C a;

Of course, you should take steps to make sure that this isn't necessairy
for writing programs.



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
rajkumar@hotmail.com
Guest





PostPosted: Fri Mar 18, 2005 1:13 pm    Post subject: Re: How can I find back the name of my class? Reply with quote

use name spaces ....

put int C in one and class C in another... and use the appropriate
namespace to resolve the ambiguity

Raj


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Boat
Guest





PostPosted: Fri Mar 18, 2005 1:18 pm    Post subject: Re: How can I find back the name of my class? Reply with quote

"lulu yao" <lulu.yao (AT) gmail (DOT) com> wrote

Quote:
Hi all,

see the following excerpt, just for test

======
int C;

class C {
...
};

...

C a; // failed to compile
======

How can I indicate compiler I want a class name rather than variable
name?

The straightforward, obvious (?) way:

class C a;



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Maxim Yegorushkin
Guest





PostPosted: Sat Mar 19, 2005 12:07 am    Post subject: Re: How can I find back the name of my class? Reply with quote

lulu yao <lulu.yao (AT) gmail (DOT) com> wrote:

Quote:
======
int C;

class C {
...
};

...

C a; // failed to compile
======

How can I indicate compiler I want a class name rather than variable
name?

class C a;

--
Maxim Yegorushkin

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ivan Vecerina
Guest





PostPosted: Sat Mar 19, 2005 12:10 am    Post subject: Re: How can I find back the name of my class? Reply with quote

"lulu yao" <lulu.yao (AT) gmail (DOT) com> wrote

Quote:
see the following excerpt, just for test

======
int C;

class C {
...
};

...

C a; // failed to compile
======

How can I indicate compiler I want a class name rather than variable
name?

You can write:
class C a; // will work ...

This goes back to C where enum and struct names are in a different
"namespace" (not in the C++ meaning of it) that variable names,
so their identifiers have to always be prefixed with 'enum' or 'struct'
( unless you use a typedef, i.e. typedef struct {...} MyStruct; ).

Of course, this is of little practical interest in "serious"
C++ code...


Cheers,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Shantanu Garg
Guest





PostPosted: Sat Mar 19, 2005 12:12 am    Post subject: Re: How can I find back the name of my class? Reply with quote

Quote:
see the following excerpt, just for test

======
int C;

class C {
...
};

...

C a; // failed to compile
======

class C a;

Specify clearly to compiler, what you want to create...

Quote:

How can I indicate compiler I want a class name rather than variable
name?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ben Hutchings
Guest





PostPosted: Sat Mar 19, 2005 12:15 am    Post subject: Re: How can I find back the name of my class? Reply with quote

lulu yao wrote:
Quote:
Hi all,

see the following excerpt, just for test

======
int C;

class C {
...
};

...

C a; // failed to compile
======

How can I indicate compiler I want a class name rather than variable
name?

class C a; // also "struct" will work instead of "class"

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Francis Glassborow
Guest





PostPosted: Sat Mar 19, 2005 1:01 am    Post subject: Re: How can I find back the name of my class? Reply with quote

In article <4qt_d.23722$YD4.10695 (AT) newssvr12 (DOT) news.prodigy.com>, Boat
<boat042-spam (AT) yahoo (DOT) com> writes
Quote:
int C;

class C {
...
};

...

C a; // failed to compile
======

How can I indicate compiler I want a class name rather than variable
name?

The straightforward, obvious (?) way:

class C a;

However the 'obvious' solution is not to create the problem. The
situation only exists because C placed struct/union/enum 'names' in
their own namespace (called tags) and so it was necessary for
compatibility reasons to allow the above syntax. However no sane
programmer would voluntarily use it.


--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.