首页 > 解决方案 > 这个对象声明有什么问题?

问题描述

#include <iostream>
using namespace std;

class A {
    public:
        int x;
    A() {
        x=1;
        cout << x <<endl;
    }
};

int main()
{
    A b();
    cout << b.x << endl;
    return 0;
}

运行此程序会导致编译错误:错误:请求'b'中的成员'x',它是非类类型'A()' "cout<< bx <

标签: c++classobject

解决方案


推荐阅读