嘿小黑子 2019-08-28 17:08 采纳率: 0%
浏览 305

C++关于对象数组初始化的问题。

最近刚学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;
}

Valid XHTML.

Valid XHTML.

Valid XHTML

  • 写回答

1条回答 默认 最新

  • qtchen_1988 2019-08-29 10:43
    关注
    Point(Point& p)
    改成
    Point(const Point& p)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码