下面是我的.h文件中RGD:如何为类私有初始化的默认值
#include <iostream>
#include <string>
using namespace std;
class ClassTwo
{
private:
string sType;
int x,y;
public:
void setSType(string);
void setX(int);
void setY(int);
string getSType();
int getX();
int getY();
};
我想建造2构造函数。
哪个构造函数1将没有参数,将所有int值初始化为0,并将字符串初始化为空字符串。
构造函数2将使用get方法获取sType,x和y参数。
但我怎么做到这一点。
ClassTwo() : sType(), x(), y() {}
您可以选择与初始化为清楚更明确:
ClassTwo() : sType(""), x(0), y(0) {}
你可以,我应该在我的cpp文件或.h文件中
见【什么是会员变量列表后面的冒号在一个构造函数好?](http://stackoverflow.com/questions/210616/what-is-the-member-variables-list-after-the-colon-in-a-constructor-good -for?lq = 1) –