如代码中所示,我创建了一个类Punkt
(意思是德语)。这是一个array[2]
类型来保存x和y轴数据。代码还没有完成和正确,我只是想让它一步一步开始。 行:selfcreates class array [2]正在导致问题
bool contains (Punkt &p){
Punkt ConTemp;
*ConTemp = &p;
是造成问题。用codeblocks编译给我错误:
no match for operator [] (operand types arr punkt and int).
问题在哪里?
enter code here
#include <iostream>
#include <array>
using namespace std;
class Punkt {
public: int XYCoord [2]={};
void setupCoord (int x, int y){
XYCoord[0]=x;
XYCoord[1]=y;
}
};
class Rechteck {
Punkt ReCoordLu,ReCoordRo;
double flaeche(double x, double y){
double xy=x*y;
return xy;
}
bool contains (Punkt &p){
Punkt ConTemp;
*ConTemp = &p;
if (ConTemp[0]>=&&ReCoordLu[0]&&ConTemp[1]>=&&ReCoordLu[1]&&
ConTemp[0]<=&&ReCoordRo[0]&&ConTemp[1]<=ReCoordRo[1]){
return true;}
else{
return false;}
};
bool contains (Rechteck &){
if (1){
return true;}
else
return false;
}
};
int main()
{
/* Rechteck sharedRectangle (Rechteck a , Rechteck b){
Rechteck c;
return Rechteck c;
} */
Punkt P1,P2;
P1.setupCoord(1,1);
P2.setupCoord(5,5);
cout<<"hello"<<P2.XYCoord[0];
return 0;
};
当然,无论你喜欢什么,你都可以自由地命名你的类,方法和变量,但我强烈推荐@ Aziuth的建议是仅仅使用英语。 – domsson