如代碼中所示,我創建了一個類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