没有匹配的“运营商<<”
No match for 'Operator<<'
在此程序中,我得到了错误
[错误]"操作员&lt;&lt;''无匹配(操作数类型是'std :: ostream {aka std :: basic_ostream}'和'numcall')
我不明白如何摆脱它!
#include<iostream>
using namespace::std;
class numcall
{
int a,b;
public:
numcall(int c,int d)
{
c = a;
c = b;
cout<<"Your First num is " << c << endl << "Your Second num is "<< d << endl;
cout << "You are in PARAMETER CONSTRUCTOR";
}
numcall(int u)
{
u = a;
b = 0;
cout << "Your First num is " << u << endl << "Your Second num is " << b << endl;
cout << "You are in PARAMETER CONSTRUCTOR";
}
numcall()
{
}
};
int main(void)
{
numcall x = numcall();
numcall y = numcall(3,4);
numcall z = numcall(3);
cout << x << endl << endl << y << endl << endl << z << endl;
}
您尚未为类numcall
定义<<
操作员,因此编译器不知道如何应用。
因此定义它。
您需要为&lt;&lt;流操作员,否则他不知道要打印什么。
friend ostream &operator<<(ostream &os, const numcall &numcall1) {
os << "a: " << numcall1.a << " b: " << numcall1.b;
return os;
}
这只是实现的一个示例。
顺便说一句,还有其他错误:c =一种分配给c的手段,您想以相反的方式做。欢迎来到编程世界伴侣;)
相关文章:
- 呼叫运营商<<临时
- 两个运营商的一些奇怪的冲突<<
- 如何在 CPP 中访问家长的运营商
- 如何明确调用好友流运营商
- 私有运营商删除会触发 GCC 和 Clang 的编译时错误,但不会在 MSVC 上触发编译时错误
- 使用运营商New分配的数据结构是否有任何副作用
- "Inheriting"移动运营商?
- 朋友ostream&运营商<<无法访问私人会员
- 为什么在下面的代码返回类型中是用于运营商重载的类类型
- 范围的枚举(枚举类)关系运营商
- 为什么“操作员”需要const但不是为“运营商&lt;”
- 对这两个分配运营商之间的不同感到困惑
- 我的班级意外加法运营商
- OpenACC - C++"新"运营商问题
- c 对运营商的一致性是新的,有多少重要
- 为什么我不能使私人运营商成为新的并使用默认实现?
- 全球取代所有新运营商
- 包装C 朋友在Cython中的非会员运营商
- 没有匹配的“运营商&lt;&lt;”
- 运营商&lt;&lt;无法访问班级的私人int