帮我看一下这个程序,总是错误提示cannot convert from 'int' to 'const class A'

u010179812 u010179812 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <iostream>
using namespace std;
class A
{
public:
void set(int x)
{
i = x;
}
int get()
{
return i;
}

private:
int i;
};

class B
{
public:
B(int a, int b, int c):x(a), width(b), length(c)
{

cout<<"长方体的面积为:"<<width.get()*length.get()<<endl;
}


private:
int x;
A width;
A length;
};

int main()
{
B b(10, 20, 30);

return 0;
}
错误提示为cannot convert from 'int' to 'const class A',但是我并没有将A的对象设为常量呀。
...全文
评论 6
收藏 已收藏
分享
返回顶部
u010179812
C++ 语言 65,214 成员 250,514 内容