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;
};
};
Printable View
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;
};
};
no, thats illegal as your compiler tells you
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.
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 asQuote:
Originally 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.
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. :)