gpt4 book ai didi

c++ - 没有匹配的调用函数

转载 作者:行者123 更新时间:2023-11-30 03:40:38 25 4
gpt4 key购买 nike

<分区>

我在代码块中创建了非常简单的 C++ 项目。我有头文件 (CVector.h)、源文件 (CVector.cpp) 和主要代码 (code.cpp)。当我尝试编译代码时,我收到以下消息:

CVector.cpp|22|error: no matching function for call to 'CVector::CVector()'|

代码.cpp

#include <iostream>
#include "CVector.h"
using namespace std;

int main () {
CVector vec1(1,2);
CVector vec2 (3,4);
cout << "vec1 data "; vec1.printData();
cout << "vec2 data "; vec2.printData();

cout << "vec1 area: " << vec1.area() << endl;
cout << "vec2 area: " << vec2.area() << endl;

return 0;
}

CVector.h

#ifndef CVECTOR_H
#define CVECTOR_H


class CVector
{
int x,y;
public:
CVector (int, int);
int area();
void printData ();
CVector operator+ (CVector param );
};

#endif // CVECTOR_H

CVector.cpp

#include <iostream>
#include "CVector.h"
using namespace std;

CVector::CVector (int a, int b) {
x=a;
y=b;
}

int CVector::area() {return x*y;}

void CVector::printData(){
cout << "X = " << x << ", Y = " << y << endl;
}

CVector CVector::operator+ (CVector param )
{
CVector temp;
temp.x=x + param.x;
temp.y=y + param.y;
return temp;
}

错误与运算符重载函数有关,因为我注释该函数时编译没有问题。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com