Standard Constructor with CPoint argument in MFC
How can I declare a standard constructor in MFC that expects a CPoint argument, e.g.
class CObj {
public:
CObj(CPoint pt = ???, float x = 10.0f, int n = 10);
...
I tried
开发者_运维问答CObj(CPoint pt = (10,10), float x = 10.0f, int n = 10);
which compiled just fine, but only pt.x got the value 10 while pt.y became 0.
Thanks, RS
I believe something like this should work:
CObj(Cpoint pt = CPoint(10,10), float x = 10.0f, int n = 10);
Edit: It sure seems to work for me:
#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;
}
Result:
x.x = 10 x.y = 10
精彩评论