Declaring Objects of classes

Hey guys,

Is it possible to declare an object with same name for two classes?
for example:
class A

Class B

int main()
A X;
B X;
No, not within the same scope. You can't have two variables of the same name in the same scope, regardless of whether they're classes or built-in types.

Why would you ever want to do this? How would the compiler know which one you meant when you wrote a line of code that uses "X"? Why would you want to make your code harder to understand for yourself and other readers?
that should be fine.
Mikeyboy, you are right, i got your point, thanks.
Manga, No its not possible, the program was not getting run.
Well, it seems you guys are right. It does not work in the same scope.

Good to know.
Topic archived. No new replies allowed.