C++ 我对范围中未声明的错误类有问题

C++ 我对范围中未声明的错误类有问题,c++,C++,我正在编译这些程序。在centOS上Complex.h、Complex.cpp和project1_task1.cpp我在VisualStudio中编译了这段代码,但在centOS中得到了错误。这是一节课 复合物 #ifndef COMPLEX_H #define COMPLEX_H class Complex { private: double realPart; double imaginaryPart; public: Complex(double real = 0

我正在编译这些程序。在centOS上Complex.h、Complex.cpp和project1_task1.cpp我在VisualStudio中编译了这段代码,但在centOS中得到了错误。这是一节课

复合物

#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
Complex.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;
}
#包括
#包括“Complex.h”
使用名称空间std;
复数::复数(双实数,双imag)
{
realPart=real;
imaginaryPart=imag;
}
双复数::getReal(){
返回此->realPart;
}
双复数::getImag(){
返回此->图像部分;
}
void Complex::setReal(双实){
realPart=real;
}
void Complex::setImag(双imag){
imaginaryPart=imag;
}
void Complex::print(){
如果(realPart!=0)

cout因为linux文件系统通常区分大小写,所以请在

project1_task1.cpp
替换

#include"complex.h"


因为linux文件系统通常区分大小写,所以请在

project1_task1.cpp
替换

#include"complex.h"


文件名是complex.h还是complex.h?Linux文件系统通常区分大小写。应该是complex.h和complex.cpp那么您的
#include
行在project1_task1.cpp中有错误,那么关于找不到文件也应该有错误,尽管可能存在不同的文件名complex.h或complex.h?Linux文件系统通常是ally区分大小写。应该是复杂的.h和复杂的.cpp然后,您的
#include
行在project1_task1.cpp中出错,然后还应该有一个关于找不到文件的错误,尽管可能存在不同的文件