consider i have two classes A and B. Is it wrong declaring a object of
type A with name B?
class A{}
class B{}
A B;
Why is it wrong?
It is not.
[3.3/4]
Given a set of declarations in a single declarative region, each of which
specifies the same unqualified name,
? they shall all refer to the same entity, or all refer to functions and
function templates; or
? exactly one declaration shall declare a class name or enumeration name
that is not a typedef name and the other declarations shall all refer to
the same object or enumerator, or all refer to functions and function
templates; in this case the class name or enumeration name is hidden.
So what you are doing is not illegal, but you are hiding class B. As a
matter of coding style, however, I would stay away from such things.
Best
Kai-Uwe Bux