ファイルを読み取って、dequeに格納するための独自のクラスを作成しています。このような
class point{
public:
void setX(float n)
{
x = n;
}
void setY(float m)
{
x = m;
}
float x;
float y;
};
int main(){
ifstream file("curveData.txt");
float x;
float y;
deque<point> dqu;
point tempPt;
while(file >> x >> y){
cout << x << ' ' << y << endl;
tempPt.setX(x);
tempPt.setY(y);
cout << tempPt.x << ' ' << tempPt.y << endl;
// to check it was initialized correctly
cout<<endl;
dqu.push_back(tempPt);
}
system ("pause");
return 0;
}
whileループ内では、最初のcoutは正しい値を表示しますが、tempPtのxとyの値を初期化した後、値を表示しようとすると、値が正しく初期化されません。y値はTempPt.xに保存され、y値はすべてのポイントで同じである奇妙な数値です。何が欠けていますか。申し訳ありませんが、C++は初めてです。