当我运行此操作时,我不断收到以下错误。任何帮助?运营商的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'函数返回。 –