我在范围内未声明的错误类有问题
I am having problem with the error class undeclared in scope
我正在编译这些程序。Complex.h、Complex.cpp 和 centOS 上的 project1_task1.cpp 我在Visual Studio中编译了这个精细,但是我在centOS中得到了错误。这是针对一个类的。
复杂.h
#ifndef COMPLEX_H
#define COMPLEX_H
class Complex
{
private:
double realPart;
double imaginaryPart;
public:
Complex(double real = 0, double imag = 0); //constructor that initializes the complex number by default arguments
double getReal(); //get function that returns the real part of the complex number
double getImag(); //get function that returns the imaginary part of the complex number
void setReal(double real); //set function that sets the real part of the complex number
void setImag(double imag); //set function that sets the imaginary part of the complex number
void print(); //function that displays the complex number
};
#endif
复杂.cpp
#include <iostream>
#include "Complex.h"
using namespace std;
Complex::Complex(double real, double imag)
{
realPart = real;
imaginaryPart = imag;
}
double Complex::getReal() {
return this->realPart;
}
double Complex::getImag() {
return this->imaginaryPart;
}
void Complex::setReal(double real) {
realPart = real;
}
void Complex::setImag(double imag) {
imaginaryPart = imag;
}
void Complex::print() {
if (realPart != 0)
cout << realPart;
if (imaginaryPart != 0)
{
if (imaginaryPart == 1)
cout << "+i";
else if (imaginaryPart == -1)
cout << "-i";
else if (imaginaryPart > 0 && realPart != 0)
cout << " + " << imaginaryPart << "i";
else
cout << imaginaryPart << "i";
}
cout << endl;
}
这是project1_task1.cpp
#include <iostream>
#include"complex.h"
using namespace std;
int main()
{
Complex c;
c.setReal(2);
c.setImag(3);
c.print();
Complex c1(4);
c1.setImag(5);
c1.print();
Complex c2(6, 7);
c2.print();
return 0;
}
当我在 centOS 中编译时,我不断得到 Complex,而不是在 project1_task1.cpp 中定义。
我该如何解决这个问题?
由于 Linux 文件系统通常区分大小写,因此
在project1_task1.cpp
替换
#include"complex.h"
跟
#include"Complex.h"
相关文章:
- 我似乎对if/else的基本语句有问题:/
- posix_spawn():使用posix_scawn()时的错误处理问题
- 输出错误,问题是找到总和5000位数字cpp
- 我在范围内未声明的错误类有问题
- 为什么这段代码给我错误? 有没有自错?
- 我的C++语言蛮力算法有问题
- C++泛型类错误,问题出在哪里?
- 我关于函数"Assert"的C++代码有问题
- 标准对此指向成员函数类型模板参数有何说明?是我的代码有误,还是 MSVS 16.6 有问题?
- C++类中的友元函数有问题?
- 使用STL对用户输入数组进行排序的错误有什么解决方案吗?
- 我对数组即 0x6dfe78 有问题
- Microsoft Visual中的此链接器错误有什么问题
- 我在 c++ 中的 AES 代码有问题。明文正在更改,但加密邮件是相同的。我找不到我的错误
- 对简单的帐户检查程序有问题?程序返回编译错误,指出"no match for 'operator||' unsure of how to fix?"
- __cdecl _unlock在声明指向指针的点抛出线程错误时与 VS C++ 2010 有问题
- Assert()函数抛出一个错误——操作符有问题
- 代码在我的系统上运行良好,但在USACO上出现分段错误.有什么问题吗?
- Playpen错误有问题
- 我的代码有问题,因为我无法弄清楚为什么会收到错误。这是代码: