N
Nan Li
I ran into the following code. It seems you can have a class and a
variable/function share the same name. This is a little confusing,
though understandable. Also it's the first time I saw the notation
'class A' in creating the object.
Is this kind of usage mentioned in any book, web page or the standard?
I'd like to know more details about this code.
Thanks !
#include <iostream>
using std::cout;
using std::endl;
struct A
{
A() { cout << "A::A" << endl; }
};
int A = 1; //one of there two is ok
void A() {} //but not both
int main()
{
class A a;
cout << A << endl;
}
variable/function share the same name. This is a little confusing,
though understandable. Also it's the first time I saw the notation
'class A' in creating the object.
Is this kind of usage mentioned in any book, web page or the standard?
I'd like to know more details about this code.
Thanks !
#include <iostream>
using std::cout;
using std::endl;
struct A
{
A() { cout << "A::A" << endl; }
};
int A = 1; //one of there two is ok
void A() {} //but not both
int main()
{
class A a;
cout << A << endl;
}