小编AK *_*K d的帖子

为什么我收到 [错误] 没有匹配的函数来调用“car::car()”

我已经用两个成员变量 a 和 b 创建了两个类 car 对象……我想创建一个新对象,其 a 和 b 是我之前创建的对象的 a 和 b 的乘积。

#include<iostream>
using namespace std;
class car
{
    private:
        int a,b;
    public:
        car(int x,int y)
        {
            a=x;
            b=y;
        }
        void showdata()
        {
            cout<<a<<" "<<b<<endl;
        }
        car add(car c)   // to multiply 'a' and 'b' of both objects and assigning to a new 
                            object 
        {
            car temp;    // new object of class car
            temp.a = a*c.a;   
            temp.b = b*c.b;
            return temp;
        }
        
};
int main()
{
    car …
Run Code Online (Sandbox Code Playgroud)

c++ oop constructor overloading operator-keyword

1
推荐指数
1
解决办法
54
查看次数

标签 统计

c++ ×1

constructor ×1

oop ×1

operator-keyword ×1

overloading ×1