我在范围内未声明的错误类有问题

I am having problem with the error class undeclared in scope

本文关键字:错误 有问题 未声明 范围内      更新时间:2023-10-16

我正在编译这些程序。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"