如何在MFC中声明需要CPoint参数的标准构造函数,例如
class CObj {
public:
CObj(CPoint pt = ???, float x = 10.0f, int n = 10);
...
我试过
CObj(CPoint pt = (10,10), float x = 10.0f, int n = 10);
编译得很好,但只有pt.x得到值10而pt.y变为0。
谢谢,RS
答案 0 :(得分:0)
我相信这样的事情应该有效:
CObj(Cpoint pt = CPoint(10,10), float x = 10.0f, int n = 10);
编辑:这似乎对我有用:
#include <iostream>
struct CPoint {
int x, y;
CPoint(int x_, int y_) : x(x_), y(y_) {}
};
class CObj {
CPoint p;
public:
CObj(CPoint pt = CPoint(10,10), float x = 10.0f, int n = 10) : p(pt) {
std::cout << "x.x = " << p.x << "\tx.y = " << p.y << std::endl;
}
};
int main() {
CObj x;
return 0;
}
结果:
x.x = 10 x.y = 10