小编use*_*254的帖子

C++错误:无法将参数1从'int'转换为'const [class name]

我正在写一个类来加,减和乘多项式.我看到以下错误:

错误C2664:'Poly :: Poly(const Poly&)':无法将参数1从'int'转换为'const Poly

来自这个声明:

return p;  // in the evaluate() function
Run Code Online (Sandbox Code Playgroud)

有谁知道如何纠正这个?

首先十分感谢.-Ryan

这是完整的代码:

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

class Poly
{
private:

//  int ord;                            // the order of the polynomial
//  int coeff[100];

public:

    int ord;                            // the order of the polynomial
    int coeff[100];


    int a, b, c;
    Poly();                             // constructor
    Poly addition(Poly b);              // adds 2 polynomials
    Poly subtraction(Poly b);           // subtracts 2 polynomials
    Poly multiplication(Poly b);        // multiplies 2 …
Run Code Online (Sandbox Code Playgroud)

c++ struct class

0
推荐指数
1
解决办法
4165
查看次数

C++:为什么返回内存地址而不是公式值?

我正在写一个类来添加,减去和乘法多项式(现在进行1周!).无论如何,代码编译,但我看到输出中似乎是内存地址.

我无法弄清楚为什么会这样.

任何人都可以引导我朝着正确的方向前进吗?

在此先感谢您的光临!瑞安

代码:

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

class Poly
{
private:

//  int ord;                            // the order of the polynomial
//  int coeff[100];

public:

    int ord;                            // the order of the polynomial
    int coeff[100];


    int a, b, c;
    Poly();                             // constructor
    Poly addition(Poly b);              // adds 2 polynomials
    Poly subtraction(Poly b);           // subtracts 2 polynomials
    Poly multiplication(Poly b);        // multiplies 2 polynomials
    int evaluate(int);                  // uses Horner's method to compute and return the …
Run Code Online (Sandbox Code Playgroud)

c++ class polynomials

-2
推荐指数
1
解决办法
287
查看次数

标签 统计

c++ ×2

class ×2

polynomials ×1

struct ×1