为什么我收到与'operator^'不匹配的错误
Why do i get an error no match for 'operator^'
我得到一个错误
10:13: error: no match for 'operator^' (operand types are 'std::basic_ostream<char>' and 'int')
10:13: note: candidates are:
In file included from /usr/include/c++/4.9/ios:42:0,
from /usr/include/c++/4.9/ostream:38,
from /usr/include/c++/4.9/iostream:39,
from 2:
/usr/include/c++/4.9/bits/ios_base.h:161:3: note: std::_Ios_Iostate std::operator^(std::_Ios_Iostate, std::_Ios_Iostate)
operator^(_Ios_Iostate __a, _Ios_Iostate __b)
^
代码是
// Example program
#include <iostream>
#include <string>
int main()
{
int a=1;
int b=2;
std::cout<<a^b;
}
operator ^
可以使用哪些操作数
根据运算符优先级,operator<<
的优先级高于operator^
。所以std::cout<<a^b;
和(std::cout<<a)^b;
是等价的;(std::cout<<a)
将通过引用返回std::cout
,这是std::basic_ostream<char>
;正如错误信息所说,您不能使用std::cout
(std::basic_ostream<char>
)和int
调用operator^
。
可以使用括号指定操作数与操作符绑定的优先级。
std::cout << (a^b);
// ~ ~
相关文章:
- 我在 .h 中有一个枚举类,并且在.cpp错误中有一个运算符重载:与"运算符<<不匹配
- 为什么我收到错误:"运算符<<不匹配?
- 错误:"模板<类_Tp,类_Dp>类 std::unique_ptr"的模板参数列表中参数 1 的类型/值不匹配
- 如何摆脱C++中的枚举不匹配错误?
- 为什么此代码编译 (C++11) 而没有类型不匹配错误
- C++ sigc::mem_fun 中的“呼叫不匹配”错误
- C++ lambda 函数中的“运算符=不匹配”错误
- C++,与"运算符="不匹配...错误
- 将构造函数添加到boost.python子类导致参数不匹配错误
- 基本代码中的"运算符=不匹配"错误
- 运算符重载,但仍然"与运算符不匹配"错误
- C++ - 模板 + 'using' 子句 - 参数不匹配错误
- 模板模板参数 - 类型/值不匹配错误
- 新建/删除运算符不匹配错误的严重程度
- c++代码中的参数不匹配错误
- 类型值与向量不匹配错误
- C++ 运算符不匹配<<错误
- LNK2038,迭代器不匹配错误,需要忽略
- QT5迁移和Boost:if.hp:宏参数不匹配错误
- x11 xGetImage不匹配错误