Can you have a class object with the same name as the class?
Example:
I ask because the compiler doesn't seem to understand person.id, etc.Code:class Person { public: struct person { char name[20]; int id; }; };
Can you have a class object with the same name as the class?
Example:
I ask because the compiler doesn't seem to understand person.id, etc.Code:class Person { public: struct person { char name[20]; int id; }; };
Okay. I figured it must be. Thanks. I was doing an assignment, which was to convert a program to a class-based program. I decided to ditch the struct alltogether as it is sort of redundant now.
Last edited by Ricochet; 12-11-2003 at 02:22 AM.
Actually, that class is legal as you have it, since 'Person' is different than 'person' (C++ is case-sensitive). It is illegal for them to be the exact same (with the same case). Of course, I don't think its a good idea anyway to be naming two different things with the same name differing only by case, so its probably a good idea that you changed it.
That's because you must access it asOriginally posted by Ricochet
Can you have a class object with the same name as the class?
Example:
I ask because the compiler doesn't seem to understand person.id, etc.Code:class Person { public: struct person { char name[20]; int id; }; };
Person.person.id
It'd really be best to come up with better identifiers, though.
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
Oh okay. Well that's interesting to know at least. Though I think I'll try not to do it. I just got rid of the struct alltogether. It made things easier inside and outside the class.