在线等。错误提示“no operator">>" matches these operands”怎么修改?谢谢

tigercoco 2012-06-27 10:47:36
是一个计算一元多项式的加法数组实现,一个数组放两个多项式的系数,另一个放指数,一个数组放系数相加后的结果。指数为0输入0。大部分函数中的cin cout都有这样的问题“no operator matches these operands”谢谢
#include<iostream>
#include <stdlib.h>
#include <string>
#define degree 6

using namespace std;
class poly{

public:

void creat_coe(int);
void creat_exp(int);
void print();
void add();

};

poly coef[6], expo[6], result[6];


void poly::creat_coe(int n){
cout<<"Please enter two polynomial numbers' coefficients matching respective exponents ,if there is no such exponent in each term,please enter 0 "
<<"each number has max 3 terms"<<endl;
for(int i = 0; i < n; i++) {
cout<<"Please enter "<<i+1<<"coefficient:"; //循环输入第i个系数
cin >> coef[i]; //no operator"<<" matches these operands;
}
}
void poly::creat_exp(int n){
cout<<"Please enter two polynomial numbers' exponents matching respective coefficients from high order to low ,if there is no such exponent in each term,please enter 0 "
<<"each number has max 3 terms"<<endl;

for(int i = 0; i < n; i++) {
cout<<"Please enter "<<i+1<<"exponnet:"; //循环输入第i个指数
cin >> expo[i]; //no operator"<<" matches these operands;
}
}
void poly::add(){
for(int i=0; i<3; i++)
result[i]= coef[i] + coef[i+2];

}
void poly ::print(){
for(int i=0; i<6; i++)
cout << result[i] << expo[i]<<" "; // no operator << matches these operands

}
int main(){
poly number;
int n;
cout<<"Please enter terms of tow polynomials :" <<endl;
cin >> n;
number.creat_coe(n);
number.creat_exp(n);
number.add();
number.print();


return 0;


}
...全文
1822 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tongzhipeng5699 2012-06-27
  • 打赏
  • 举报
回复
你的poly类一个属性都没有?不知道你的意图是什么,你的add里面还有加法,+也需要重载,给一个复数运算的重载的例子,你就懂了。


#include <iostream>
using namespace std;
class Complex {
public:
Complex (int r = 0, int i = 0) : m_r (r), m_i (i) {}
/*
Complex operator+ (const Complex& c) const {
return Complex (m_r + c.m_r, m_i + c.m_i);
}
*/
friend Complex operator+ (const Complex& c1, const Complex& c2) {
return Complex (c1.m_r + c2.m_r, c1.m_i + c2.m_i);
}
Complex operator+ (int n) {
return Complex (m_r + n, m_i);
}
Complex operator- (const Complex& c) const {
return Complex (m_r - c.m_r, m_i - c.m_i);
}
/*
Complex& operator+= (const Complex& c) {
// return *this = *this + c;
m_r += c.m_r;
m_i += c.m_i;
return *this;
}
*/
friend Complex& operator+= (Complex& c1, const Complex& c2) {
return c1 = c1 + c2;
}
Complex& operator-= (const Complex& c) {
return *this = *this - c;
}
Complex operator- (void) {
return Complex (-m_r, -m_i);
}
const Complex operator++ (int) {
Complex c = *this;
m_r++;
m_i++;
return c;
}
Complex& operator++ (void) {
m_r++;
m_i++;
return *this;
}
const Complex operator-- (int) {
Complex c = *this;
m_r--;
m_i--;
return c;
}
Complex& operator-- (void) {
m_r--;
m_i--;
return *this;
}
private:
int m_r;
int m_i;
friend ostream& operator<< (ostream&, const Complex&);
friend istream& operator>> (istream&, Complex&);
};
ostream& operator<< (ostream& os, const Complex& c) {
os << "(" << c.m_r << "+" << c.m_i << "i)";
return os;
}
istream& operator>> (istream& is, Complex& c) {
return is >> c.m_r >> c.m_i;
}
int main (void) {
Complex c1 (3, 4);
cout << c1 << endl; // operator<<(cout,c1)
// operator<<(cout,c1).operator<<(endl);
Complex c2 (5, 6);
// cin >> c2; // operator>> (cin, c2)
Complex c3 = c1 + c2;
// c3 = c1.operator+ (c2)
// c3 = operator+ (c1, c2)
cout << c1 << '+' << c2 << '=' << c3 << endl;
cout << c3 << '-' << c2 << '=' <<c3-c2<<endl;
Complex c4 (c1);
(c4 += c2) += c2;
// c4.operator+= (c2);
// operator+= (c4, c2);
cout << c4 << endl;
(c4 -= c2) -= c2;
cout << c4 << endl;
cout << -c4 << endl;
int n = 10;
cout << n++ << endl; // 10
cout << n << endl; // 11
// (n++)++;
int m = 10;
cout << ++m << endl; // 11
cout << m << endl; // 11
++++m;
cout << m << endl;
cout << c1++ << endl;
// c1.operator++ (0)
cout << c1 << endl;
// c1++++;
cout << ++c2 << endl;
cout << c2 << endl;
++++c2;
cout << c2 << endl;
cout << c2+100 << endl; // c2.operator+(100)
return 0;
}


[Quote=引用 4 楼 的回复:]
[Quote=引用 3 楼 的回复:]
[Quote=引用楼主 的回复:]
是一个计算一元多项式的加法数组实现,一个数组放两个多项式的系数,另一个放指数,一个数组放系数相加后的结果。指数为0输入0。大部分函数中的cin cout都有这样的问题“no operator matches these operands”谢谢
#include<iostream>……
[/Quote]
W170532934 2012-06-27
  • 打赏
  • 举报
回复
因为expo[i];是自己定义的类型,你还是在该类型里面进行操作符重载<<和>>吧
tigercoco 2012-06-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
[Quote=引用楼主 的回复:]
是一个计算一元多项式的加法数组实现,一个数组放两个多项式的系数,另一个放指数,一个数组放系数相加后的结果。指数为0输入0。大部分函数中的cin cout都有这样的问题“no operator matches these operands”谢谢
#include<iostream>
#include <stdlib.h>……
[/Quote]可否告知怎样重载呢?
谢谢...
N0bug 2012-06-27
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
是一个计算一元多项式的加法数组实现,一个数组放两个多项式的系数,另一个放指数,一个数组放系数相加后的结果。指数为0输入0。大部分函数中的cin cout都有这样的问题“no operator matches these operands”谢谢
#include<iostream>
#include <stdlib.h>
#include <string>……
[/Quote]
expo[i];是一个poly类型 你又没有重载">>" 当然cin不进去
tigercoco 2012-06-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
#include<iostream>
[/Quote]加上问题依然存在。刚看了下自己写的,本身有isostream。请继续指教。
善良超锅锅 2012-06-27
  • 打赏
  • 举报
回复
#include<iostream>
FASMARM v1.42 This package is an ARM assembler add-on for FASM. FASMARM currently supports the full range of instructions for 32-bit and 64-bit ARM processors and coprocessors up to and including v8. Contents: 1. ARM assembly compatibility 2. UAL and pre-UAL syntaxes 3. IT block handling 4. Alternate encodings 5. Output formats 6. Control directives 7. Data definitions 8. Defining registers lists inside macros 9. Half-precision number formatting 10. Variants supported 11. Further information 12. Version history _______________________________________________________________________________ 1. ARM assembly compatibility There are a few restrictions how the ARM instruction set is implemented. The changes are minor and mostly have a minor impact. For the most part the basic instruction outline is the same. Where possible the original style is used but there are some differences: Not everything matches the ARM ADS assembly style, where possible the original style is used but there are some differences 1) label names cannot begin with a digit 2) CPSIE and CPSID formats are changed, use "iflags_aif" form instead of "aif" (eg. "CPSIE iflags_i" instead of "CPSID i") 3) SRS with writeback must have a separating space after the mode number and before "!" (eg. "SRSDB 16 !" instead of "SRSDB 16!") 4) macro, rept, irp, format, if, virtual etc. are all significant changes from the ARM ADS, so you will need to re-write those sections of existing code Original ARM Syntax | fasmarm Syntax ----------------------+---------------------- cpsie a | cpsie iflags_a | srsdb #29! | srsdb #29 ! ;or, | srsdb 29 ! _______________________________________________________________________________ 2. UAL and pre-UAL syntaxes fasmarm supports the original pre-UAL syntax and the newer UAL syntax. These two syntaxes only affect THUMB encodings. UAL stands for: Universal Assembly Language. pre-UAL syntax is selected wi

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧