Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;超载>&燃气轮机;操作人员_C++_Class_Overloading - Fatal编程技术网

C++ c++;超载>&燃气轮机;操作人员

C++ c++;超载>&燃气轮机;操作人员,c++,class,overloading,C++,Class,Overloading,我想将>重载添加到我的类中,但当我编译它时,编译器会给我以下错误: In function 'std::istream& operator>>(std::istream&, const Dogru&)': [Error] ambiguous overload for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}'

我想将
>
重载添加到我的类中,但当我编译它时,编译器会给我以下错误:

In function 'std::istream& operator>>(std::istream&, const Dogru&)':
[Error] ambiguous overload for 'operator>>' (operand types are
        'std::istream {aka std::basic_istream<char>}' and 'const int')

您需要修改
dog
so的状态

istream& operator>> (istream &in, const Dogru &dog)
                                // ^^ const should be removed

使用
const
引用进行重载
您不能将读取的值放入
const
对象中。删除
常量

istream& operator>> (istream &in, Dogru &dog){
    in >> dog.yon_x;
    in >> dog.yon_y;
    in >> dog.yon_z;    
    return in;
}
详细信息:
const
表示“我的代码不会改变此变量”。但输入操作的全部要点是改变变量


你可以超载
ostream&operator哦,我真的忘了。太多了
istream& operator>> (istream &in, Dogru &dog){
    in >> dog.yon_x;
    in >> dog.yon_y;
    in >> dog.yon_z;    
    return in;
}