Declaring Objects of classes

Sep 13, 2013 at 1:54pm
Hey guys,

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

};
Class B
{

};
int main()
{
A X;
B X;
}
Sep 13, 2013 at 1:58pm
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?
Sep 13, 2013 at 1:59pm
that should be fine.
Sep 13, 2013 at 2:02pm
Mikeyboy, you are right, i got your point, thanks.
Manga, No its not possible, the program was not getting run.
Sep 13, 2013 at 2:18pm
Well, it seems you guys are right. It does not work in the same scope.

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