| View previous topic :: View next topic |
| Author |
Message |
lulu yao Guest
|
Posted: Thu Mar 17, 2005 9:40 pm Post subject: How can I find back the name of my class? |
|
|
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
|
Posted: Fri Mar 18, 2005 1:03 pm Post subject: Re: How can I find back the name of my class? |
|
|
"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
|
Posted: Fri Mar 18, 2005 1:05 pm Post subject: Re: How can I find back the name of my class? |
|
|
"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
|
Posted: Fri Mar 18, 2005 1:05 pm Post subject: Re: How can I find back the name of my class? |
|
|
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
|
Posted: Fri Mar 18, 2005 1:06 pm Post subject: Re: How can I find back the name of my class? |
|
|
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
|
Posted: Fri Mar 18, 2005 1:08 pm Post subject: Re: How can I find back the name of my class? |
|
|
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
|
Posted: Fri Mar 18, 2005 1:13 pm Post subject: Re: How can I find back the name of my class? |
|
|
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
|
Posted: Fri Mar 18, 2005 1:18 pm Post subject: Re: How can I find back the name of my class? |
|
|
"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
|
Posted: Sat Mar 19, 2005 12:07 am Post subject: Re: How can I find back the name of my class? |
|
|
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
|
Posted: Sat Mar 19, 2005 12:10 am Post subject: Re: How can I find back the name of my class? |
|
|
"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
|
Posted: Sat Mar 19, 2005 12:12 am Post subject: Re: How can I find back the name of my class? |
|
|
| 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
|
Posted: Sat Mar 19, 2005 12:15 am Post subject: Re: How can I find back the name of my class? |
|
|
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
|
Posted: Sat Mar 19, 2005 1:01 am Post subject: Re: How can I find back the name of my class? |
|
|
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 |
|
 |
|