C 方法无法工作
C++ Method wont work
因此,我创建了一种方法,以启动添加,乘法和等多项式的过程,但是,当安排运行start((时,编译器都会运行,但是盒子仍然空白,即使不应该。不确定我在做什么错。
有什么想法?
这是我的代码。
这是我的标题
#ifndef _POLY_GUARD
#define _POLY_GUARD
#include <iostream>
using namespace std;
class Polynomial
{
public:
Polynomial(int coef, int exp);
void start();
friend ostream & operator << (ostream &out, const vector<int> &c);
friend istream & operator >> (istream &in, const Polynomial &c);
void addPolynomials();
void multiplyPolynomials();
void evaluatePolynomial();
int findCoefficient();
int findLeadingExponent();
};
#endif
这是源代码。
#include "Polynomial.h"
#include <utility>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void Polynomial::start()
{
int choice;
std::cout << "What do you wish to do?" << std::endl;
std::cout << "1. Add two polynomials" << std::endl;
std::cout << "2. Multiply two polynomials" << std::endl;
std::cout << "3. Evaluate one polynomial at a given value" << std::endl;
std::cout << "4. Find Coefficent for a given polynomial and given exponent" << std::endl;
std::cout << "5. Find the leading exponent for a given polynomial" << std::endl;
std::cout << "6. Exit " << std::endl;
std::cin >> choice;
if (choice < 1 || choice > 6)
{
do
{
std::cout << "Invalid entry: please reenter choice" << std::endl;
std::cin >> choice;
} while (choice < 1 || choice > 6);
}
if (choice == 1)
{
}
}
最后,这是我的主要
#include "Polynomial.h"
#include <string>
#include <vector>
#include <utility>
int main()
{
Polynomial start();
system("pause");
}
阅读上面的评论与下面的示例一样有用。
因此,您有一个Polynomial
类,可以从中创建该特定类型的(实例化(对象。
class Polynomial {
public:
/// default constructor
Polynomial() = default;
/// constructor with your coef and exp parameters
/// when invoked it will use its arguments to initialize
/// the data members coef and exp.
Polynomial(int coef, int exp)
: coef(coef)
, exp(exp){};
/// your member function start()
void start();
private:
/// your private data members that
/// are initialized upon construction
/// when calling the appropriate constructor
int coef;
int exp;
};
在您的主要功能中,正如其他人提到的那样,您可以构造一个类型Polynomial
的对象,称其为app
或whatever
:
int main()
{
/// app is your object of type Polynomial
/// its coef and exp are initialized
/// using your arguments 4 and 5 respectively.
Polynomial app(4, 5);
/// now you can call you member function
app.start();
return 0;
}
根据此页面,可以在另一个函数中声明功能。
因此,您的main
函数声明了一个名为start
的函数,该函数返回Polynomial
对象,然后调用system("pause")
,然后返回。
尝试分开声明和调用方法start
:
Polynomial p;
p.start();
或
Polynomial(1, 2).start(); // pass valid parameters
因为
Polynomial start();
是最烦人的解析。
https://en.wikipedia.org/wiki/most_vexing_parse_parse
相关文章:
- C++ assigment std::list:<typename>:itrator 在 main 中工作,但在方法中它不起作用
- Poco 库 PUT 方法未按预期工作,尽管主机、方法、内容类型设置正确
- std::bind,无法让具有单个参数的方法工作
- 私有变量无法正常工作的C++getter方法(只有Java经验)
- 虚拟基类在内部如何工作?编译器如何解析对基方法的调用?
- 让类与运算符一起工作更简单的方法
- 找不到使保证返回值优化工作的方法
- C++ set_difference方法未按预期工作
- 解决方法:'can not be used when making a shared object; recompile with -fPIC'使用Cmake。使用普通的 g++ 工作
- 尝试使用 Qt 库中的 QPixmap 将图像拆分为多个块。关于他的复制方法的工作方式,我有什么不明白的吗?
- C 方法无法工作
- 我是否应该在构造函数或成员方法中进行大量初始化工作
- 请告诉我在巴泽尔拥有多平台工作空间的更好方法
- 这种奇怪的 I/O 方法是如何工作的?
- 在 Xcode 中工作的 CMake 中启用地址清理器的正确方法是什么
- 在Qt中使用工作线程将数据写入文件的正确方法是什么?
- 我试着了解方法覆盖是如何工作的,不知道为什么输出 2
- 我的重载后增量方法无法按预期工作。为什么?
- 无法使方法存在检测机制正常工作
- 在多线程中使用curl句柄的错误工作方法的替代方法