最近刚学c++,不明白这个error错在哪里。问题在main.cpp中的对象数组初始化那一行。
pointArr.h
#ifndef POINTARR_H
#define POINTARR_H
#include <iostream>
using namespace std;
class Point {
public:
Point(int m, int n) : x(m), y(n) { cout << "构造了一个Point!" << endl; count++; }
Point() : Point(0, 0) {}
Point(Point& p) : x(p.x), y(p.y) { cout << "复制构造了一个Point!" << endl; count++; }
~Point() { cout << "析构了一个Point!" << endl; count--; }
void move(int, int);
int getX() const { return x; }
int getY() const { return y; }
int showCount() const { return count; }
private:
int x, y;
static int count;
};
#endif
pointArr.cpp
#include "PointArray.h"
void Point::move(int m, int n) {
x = m;
y = n;
}
int Point::count = 0;
main.cpp
#include "pointArray.h"
#include <iostream>
using namespace std;
int main() {
Point p[2] = { Point(0, 0), Point(3, 4) }; //ERROR
return 0;
}