类变量的声明

class A
{
public:
    A(int i)
    {
        cout << "gouzaohanshu" << endl;
    }
    void he()
    {
        cout << "hello" << endl;
    }
    int *b;
};
int _tmain(int argc, _TCHAR* argv[])
{
    A a;// = A(1);     //错误
    //a->he();
    cout << sizeof(A) << endl;
    system("pause");
    return 0;
}

类的构造函数有参数,在生命类变量时必须带参数,因此必须声明为A a(1)。A a = new A(1)。

在构造函数无参数时,A a; 实例化为:A *a = new A(); A *a = new A;

猜你喜欢

转载自blog.csdn.net/yihuanyihuan/article/details/84000299