简体   繁体   English

“类”尚未声明

[英]“Class” has not been declared

First, I know that this problem has already been treated here , but I have not been able to solve it.首先,我知道这个问题已经在这里处理过了,但是我一直没能解决它。

I have several classes, which are LitteralPart, Monome, Polynome and PolynomialFraction.我有几个类,它们是 LitteralPart、Monome、Polynome 和 PolynomialFraction。 They all have to be able to use each other, (ie Monome have to be able to owns methods which could return PolynomialFraction), but when I try to compile the program, I get around 400 like它们都必须能够相互使用(即 Monome 必须能够拥有可以返回 PolynomialFraction 的方法),但是当我尝试编译程序时,我得到了大约 400 个

"Polynome" does not name a type
"Monome" is not declared
"LitteralPart" is not declared in this scope

and so on.等等。

Each of headers file are as the following:每个头文件如下:

#ifndef // Variable for the file
#define // Variable for the file

#include "includes.h" // Contains several includes like <QString> or <QVector>

#include // All others class headers

class Class
{
   // Class definition
};

// Operators overloading

For example, here is the Polynome header with all errors in comment:例如,这里是 Polynome header,所有错误都在注释中:

#ifndef POLYNOME_H
#define POLYNOME_H

#include "includes.h"

#include "monome.h"
#include "polynomialfraction.h"
#include "math.h"

class Polynome
{
public:
    Polynome();
    Polynome(QString polynome);

    void setMonomeVector(QVector<Monome> monomeVector);
        /*
           "Monome" was not declared in this scope
            template argument 1 is invalid
            "Monome" was not declared in this scope
            template argument 1 is invalid
            "Monome" was not declared in this scope
            template argument 1 is invalid
            "Monome" was not declared in this scope
            template argument 1 is invalid
            "Monome" was not declared in this scope
            template argument 1 is invalid
        */

    QVector<Monome> getMonomeVector()const;
        /*
           "Monome" was not declared in this scope
            template argument 1 is invalid
            "Monome" was not declared in this scope
            template argument 1 is invalid
            "Monome" was not declared in this scope
            template argument 1 is invalid
            "Monome" was not declared in this scope
            template argument 1 is invalid
            "Monome" was not declared in this scope
            template argument 1 is invalid
        */

    int getConstantValue();
    QStringList getLitteralParts() const;

    void simplify();
    void invert();

    int getDegree() const;
    QString toString()const;

    void operator+=(Monome const& other);
        /*
            "Monome" has not been declared
            "Monome" has not been declared
            "Monome" has not been declared
            "Monome" has not been declared
            "Monome" has not been declared
         */
    void operator+=(Polynome const& other);

    void operator-=(Monome const& other);
        /*
            "Monome" has not been declared
            "Monome" has not been declared
            "Monome" has not been declared
            "Monome" has not been declared
            "Monome" has not been declared
         */
    void operator-=(Polynome const& other);

    void operator*=(int const& other);
        /*
            with "void operator*=(int const& other)";
            with "void operator*=(int const& other)";
            with "void operator*=(int const& other)";
            with "void operator*=(int const& other)";
            with "void operator*=(int const& other)";
         */
    void operator*=(Monome const& other);
        /*
            "Monome" has not been declared
            "Monome" has not been declared
            "Monome" has not been declared
            "Monome" has not been declared
            "Monome" has not been declared
         */
    void operator*=(Polynome const& other);

    void operator/=(int const& other);
        /*
            with "void operator/=(int const& other)";
            with "void operator/=(int const& other)";
            with "void operator/=(int const& other)";
            with "void operator/=(int const& other)";
            with "void operator/=(int const& other)";
        */
    void operator/=(Monome const& other);
        /*
            "Monome" has not been declared
            "Monome" has not been declared
            "Monome" has not been declared
            "Monome" has not been declared
            "Monome" has not been declared
         */
    void operator/=(Polynome const& other);

    void operator=(QString const& value);
    void operator=(const char* value);

private:
    QVector<Monome> monomeVector;
        /*
           "Monome" was not declared in this scope
            template argument 1 is invalid
            "Monome" was not declared in this scope
            template argument 1 is invalid
            "Monome" was not declared in this scope
            template argument 1 is invalid
            "Monome" was not declared in this scope
            template argument 1 is invalid
            "Monome" was not declared in this scope
            template argument 1 is invalid
        */
};

Polynome operator+(Polynome const& a, Monome const& b);
    /*
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
    */
Polynome operator+(Polynome const& a, Polynome const& b);

Polynome operator-(Polynome const& a, Monome const& b);
    /*
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
     */
Polynome operator-(Polynome const& a, Polynome const& b);
Polynome operator*(Polynome const& a, int const& b);
Polynome operator*(int const& b, Polynome const& a);
Polynome operator*(Polynome const& a, int const& b);
Polynome operator*(Polynome const& a, Monome const& b);
    /*
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
     */
Polynome operator*(Polynome const& a, Polynome const& b);

Polynome operator/(Polynome const& a, int const& b);
Polynome operator/(int const& b, Polynome const& a);
Polynome operator/(Polynome const& a, Monome const& b);
    /*
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
     */
Polynome operator/(Monome const& b, Polynome const& a);
    /*
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
        "Monome" has not been declared
     */
Polynome operator/(Polynome const& a, Polynome const& b);

#endif // POLYNOME_H

There are the same problems in all others files.所有其他文件中都存在相同的问题。

All those files, except includes.h have been placed in a subdirectory of the project, but if I use #include "polynome.h" , #include "variables/polynome.h" or even their absolute path, that changes nothing.所有这些文件,除了 includes.h 都放在项目的子目录中,但是如果我使用#include "polynome.h"#include "variables/polynome.h"甚至它们的绝对路径,那什么都不会改变。

I have put (and renamed) all my classes declarations together, so I have:我已将(并重命名)我所有的类声明放在一起,所以我有:

#ifndef VARIABLESINCLUDE_H
#define VARIABLESINCLUDE_H

#include "includes.h"
#include "math.h"

class Litteral;
class Monomial;
class Polynomial;
class PolynomialFraction;

class Litteral
{
public:
    Litteral();
    Litteral(QString value);

    QString toString() const;

    void invert();

    void setLitteral(QString litteral);
    void setExposant(int exposant);

    QString getLitteral() const;
    int getExposant() const;

    QString operator+(Litteral a);

private:
    QString litteral;
    int exposant;
};

bool operator==(Litteral const& a, Litteral const& b);
bool operator!=(Litteral const& a, Litteral const& b);

class Monomial
{
public:
    Monomial();
    Monomial(QString monome);

    QStringList getLitterals() const;

    QString toAbsoluteValueString() const;
    QString toString() const;

    void invert();

    void operator*=(int other);
    void operator*=(Litteral other);
    void operator*=(Monomial other);

    void operator/=(int const& other);
    void operator/=(Litteral const& other);
    void operator/=(Monomial const& other);

    void setCoefficient(int coefficient);
    void setLitteralVector(QVector<Litteral> litteralPartVector);
    void addLitteral(Litteral litteralPart);

    bool isNull() const;
    int getMaxPower() const;
    int getDegree() const;
    int getCoefficient() const;
    QVector<Litteral> getLitteralVector() const;

    void simplify();

private:
    QVector<Litteral> litteralPartVector;
    int coefficient;
};

Monomial operator*(Monomial const& a, int const& b);
Monomial operator*(Monomial const& a, Litteral const& b);
Monomial operator*(Monomial const& a, Monomial const& b);

Monomial operator/(Monomial const& a, int const& b);
Monomial operator/(Monomial const& a, Litteral const& b);
Monomial operator/(Monomial const& a, Monomial const& b);

class Polynomial
{
public:
    Polynomial();
    Polynomial(QString polynome);

    void setMonomialVector(QVector<Monomial> monomeVector);

    QVector<Monomial> getMonomialVector()const;
    int getConstantValue();
    QStringList getLitterals() const;

    void simplify();
    void invert();

    int getDegree() const;
    QString toString()const;

    void operator+=(Monomial const& other);
    void operator+=(Polynomial const& other);

    void operator-=(Monomial const& other);
    void operator-=(Polynomial const& other);

    void operator*=(int const& other);
    void operator*=(Monomial const& other);
    void operator*=(Polynomial const& other);

    void operator/=(int const& other);
    void operator/=(Monomial const& other);
    void operator/=(Polynomial const& other);

    void operator=(QString const& value);
    void operator=(const char* value);

private:
    QVector<Monomial> monomeVector;
};

Polynomial operator+(Polynomial const& a, Monomial const& b);
Polynomial operator+(Polynomial const& a, Polynomial const& b);

Polynomial operator-(Polynomial const& a, Monomial const& b);
Polynomial operator-(Polynomial const& a, Polynomial const& b);
Polynomial operator*(Polynomial const& a, int const& b);
Polynomial operator*(int const& b, Polynomial const& a);
Polynomial operator*(Polynomial const& a, int const& b);
Polynomial operator*(Polynomial const& a, Monomial const& b);
Polynomial operator*(Polynomial const& a, Polynomial const& b);

Polynomial operator/(Polynomial const& a, int const& b);
Polynomial operator/(int const& b, Polynomial const& a);
Polynomial operator/(Polynomial const& a, Monomial const& b);
Polynomial operator/(Monomial const& b, Polynomial const& a);
Polynomial operator/(Polynomial const& a, Polynomial const& b);

class PolynomialFraction
{
public:
    PolynomialFraction();
    PolynomialFraction(Polynomial numerator);
    PolynomialFraction(Polynomial numerator, Polynomial denominator);
    PolynomialFraction(QString numerator);
    PolynomialFraction(QString numerator, QString denominator);
    PolynomialFraction(const char* numerator);
    PolynomialFraction(const char* numerator, const char* denominator);

    QString toString() const;

    void invert();

    Polynomial getNumerator() const;
    Polynomial getDenominator() const;

    void setNumerator(Polynomial numerator);
    void setDenominator(Polynomial denominator);

    void operator+=(int const& other);
    void operator+=(Monomial const& other);
    void operator+=(Polynomial const& other);
    void operator+=(PolynomialFraction const& other);

    void operator-=(int const& other);
    void operator-=(Monomial const& other);
    void operator-=(Polynomial const& other);
    void operator-=(PolynomialFraction const& other);

    void operator*=(int const& other);
    void operator*=(Monomial const& other);
    void operator*=(Polynomial const& other);
    void operator*=(PolynomialFraction const& other);

    void operator/=(int const& other);
    void operator/=(Monomial const& other);
    void operator/=(Polynomial const& other);
    void operator/=(PolynomialFraction const& other);

    void operator=(QString const& value);
    void operator=(char* const value);

private:
    Polynomial numerator, denominator;
};

PolynomialFraction operator+(PolynomialFraction const& a, int const& b);
PolynomialFraction operator+(PolynomialFraction const& a, Monomial const& b);
PolynomialFraction operator+(PolynomialFraction const& a, Polynomial const& b);
PolynomialFraction operator+(int const& b, PolynomialFraction const& a);
PolynomialFraction operator+(Monomial const& b, PolynomialFraction const& a);
PolynomialFraction operator+(Polynomial const& b, PolynomialFraction const& a);
PolynomialFraction operator+(PolynomialFraction const& a, PolynomialFraction const& b);

PolynomialFraction operator-(PolynomialFraction const& a, int const& b);
PolynomialFraction operator-(PolynomialFraction const& a, Monomial const& b);
PolynomialFraction operator-(PolynomialFraction const& a, Polynomial const& b);
PolynomialFraction operator-(int const& b, PolynomialFraction const& a);
PolynomialFraction operator-(Monomial const& b, PolynomialFraction const& a);
PolynomialFraction operator-(Polynomial const& b, PolynomialFraction const& a);
PolynomialFraction operator-(PolynomialFraction const& a, PolynomialFraction const& b);

PolynomialFraction operator*(PolynomialFraction const& a, int const& b);
PolynomialFraction operator*(PolynomialFraction const& a, Monomial const& b);
PolynomialFraction operator*(PolynomialFraction const& a, Polynomial const& b);
PolynomialFraction operator*(int const& b, PolynomialFraction const& a);
PolynomialFraction operator*(Monomial const& b, PolynomialFraction const& a);
PolynomialFraction operator*(Polynomial const& b, PolynomialFraction const& a);
PolynomialFraction operator*(PolynomialFraction const& a, PolynomialFraction const& b);

PolynomialFraction operator/(PolynomialFraction const& a, int const& b);
PolynomialFraction operator/(PolynomialFraction const& a, Monomial const& b);
PolynomialFraction operator/(PolynomialFraction const& a, Polynomial const& b);
PolynomialFraction operator/(int const& b, PolynomialFraction const& a);
PolynomialFraction operator/(Monomial const& b, PolynomialFraction const& a);
PolynomialFraction operator/(Polynomial const& b, PolynomialFraction const& a);
PolynomialFraction operator/(PolynomialFraction const& a, PolynomialFraction const& b);

#endif // VARIABLESINCLUDE_H

Then, in all.cpp files, I replaced #include "polynome.h" by #include "variablesinclude.h" .然后,在 all.cpp 文件中,我将#include "polynome.h"替换为#include "variablesinclude.h" That solved the problem.这解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM