是否可以在类定义中创建类的对象而不使用默认构造函数?
class Vector3D {
public:
Vector3D(int x, int y, int z);
virtual ~Vector3D();
private:
int m_X;
int m_y;
int m_z;
};
class CustomClass {
private:
Vector3D m_Vec(50,50,50); //error
};
Run Code Online (Sandbox Code Playgroud)
是的,这可以做到,但语法不同:
class Vector3D {
public:
Vector3D(int x, int y, int z);
virtual ~Vector3D();
private:
int m_X;
int m_y;
int m_z;
};
class CustomClass {
private:
Vector3D m_Vec;
public:
CustomClass(): m_Vec(50,50,50) {}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
111 次 |
| 最近记录: |