yongyuan3073 2013-12-09 11:05 采纳率: 100%
浏览 2681
已采纳

基类的对象作为派生类函数的形参传递。。大家帮忙看看

class Point{
public:
Point(int xx,int yy){
x = xx;
y = yy;
}

private:
int x,y;
};

class Triangle:public Point{
public:
Triangle(Point p1,Point p2,Point p3):p1(p1),p2(p2),p3(p3){}
}
private:
Point p1;
Point p2;
Point p3;
};
上面两个类的定义在两个头文件中,在main函数中包括
#include
#include

#include "Point.h"
#include "triangle.h"
using namespace std;

int main(){
Point point(7, 11);
Point p1(1,1), p2(5,1), p3(1,4);
Triangle triangle(p1, p2, p3);
system("pause");
return 0;
}
错误是:triangle.h [Error] no matching function for call to 'Point::Point()'
这是什么原因?

  • 写回答

3条回答

  • Todd_Pointer 2013-12-09 13:16
    关注

    Triangle(Point p1,Point p2,Point p3): Point(oo,xx), p1(p1),p2(p2),p3(p3){}
    基类没有无参构造函数,需要指定使用基类的哪个构造函数。

    话说 三角形类从点类派生, 着实有些个蛋疼啊。。。楼主需要注意LSP原则

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作