// Case A
class Point {
private:
int x;
int y;
public:
Point(int i = 0, int j = 0); // Constructor
};
Point::Point(int i, int j) {
x = i;
y = j;
cout << "Constructor called";
}
// Case B:
class Point {
private:
int x;
int y;
public:
Point(int i, int j); // Constructor
};
Point::Point(int i = 0, int j = 0) {
x = i;
y = j;
cout << "Constructor called";
}
问题> Case A 和 Case B 用 VS2010 编译都没有问题。
原来我假设只有案例 A 有效,因为我记得应该在声明函数的地方引入默认参数,而不是在其定义的位置引入。有人可以纠正我吗?
谢谢