當我運行此操作時,我不斷收到以下錯誤。任何幫助?運營商的ambigious過載>>'在'getfile >>點'
ambigious overload for ‘operator >> ’ in ‘getfile >> point’
這是我在第對象代碼
istream& pp::operator >> (istream& in)
{
//error msg
string msg = "Error. Output from file, String is found instead of integer. Please check file for errors\n";
//ignore everything till next record
in.ignore(256, '[');
//store x cordinate
in >> x;
if(in.fail()){throw msg;}
//ignore everything till next record
in.ignore(256, ',');
//store y cordinate
in >> y;
if(in.fail()){throw msg;}
//ignore the rest of the records till next line
in.ignore(256, '\n');
return in;
}//end of operator >> method
這是我的主要
{
ifstream getfile;
//get filename to input data into system
cout << "\nPlease enter filename : ";
cin >> file;
getfile.open(file, ios::in);
pp pointObject();
getfile >> point;
}
這是我pp.h結構,其中你們希望看到的。
class pp
{
public:
//constructor
pp();
pp(int, int);
pp(const Point2D &pd);
//operator overloaded methods
virtual pp operator-(pp pd);
virtual bool operator<(pp pd) const;
virtual bool operator>(pp pd) const;
virtual bool operator==(pp pd);
virtual ostream& operator<<(ostream& o) const;
virtual istream& operator>>(istream& in;
//accessor,mutator methods
int getX() const;
int getY() const;
void setX(int);
void setY(int);
protected:
int x;
int y;
};
#endif
什麼是'getfile'? – Kos
顯示'點'的定義。 – trojanfoe
雖然與你的問題無關,你真的不應該'拋出'字符串。使用其中一個標準異常,比如'runtime_error',構造函數接受一個字符串作爲參數,這將由'exception :: what'函數返回。 –