简体   繁体   English

错误:C2146:语法错误:缺少';' 在标识符“ m_Employer”之前,

[英]error: C2146: syntax error : missing ';' before identifier 'm_Employer',

Along with Errors "C4430 missing type specifier int assumed" x2 , and C2061 syntax Errors Employer Code: 连同错误“ C4430缺少假定的类型说明符int” x2和C2061语法错误雇主代码:

Person.h

    #ifndef PERSON_H
    #define PERSON_H
    #include "employer.h"
    #include "position.h"
    #include <QTextStream>
    #include <QString>

    class Person
    {
    private:
        QString m_Name;
        bool m_Employed;

Getting a syntax error here and missing type specifier: 在这里出现语法错误,并且缺少类型说明符:

        Employer m_Employer;
        Position m_Position;
    public:
        Person();
        Person(QString name);
        QString toString();

syntax error here 语法错误在这里

        void setPosition(Employer &newC, Position &newP);
        void getPosition();
        void getEmployer();
    };

    #endif // PERSON_H

Person.cpp 人.cpp

    #include "person.h"

    Person::Person()
    {
        m_Name = "";
    }

    Person::Person(QString name)
    {
        m_Name = name;
    }

    QString Person::toString()
    {
        return "";
    }

    void Person::setPosition(Employer &newC, Position &newP)
    {

    }

Employer.h file: Employer.h文件:

    #ifndef EMPLOYER_H
    #define EMPLOYER_H
    #include "person.h"
    #include <QTextStream>
    #include<QString>


    class Employer
    {
    private:
        QString m_Name;
        QString m_Market;

    public:
        Employer();
        Employer(QString name, QString market);

Syntax Error Here 语法错误在这里

        bool hire(Person &newHire, Position pos);
        QString toString();
    };

    #endif // EMPLOYER_H

Employer.cpp 用人单位

    #include "employer.h"

    Employer::Employer()
    {

    }

    Employer::Employer(QString name, QString market)
    {
        m_Name = name;
        m_Market = market;
    }

    QString toString()
    {
     return "";
    }

Position.h file: Position.h文件:

    #ifndef POSITION_H
    #define POSITION_H
    #include <QTextStream>
    #include <QString>

    class Position
    {
    private:
        QString m_Name;
        QString m_Description;

    public:
        Position();
        Position(QString name, QString description);
        ~Position();
        QString toString();
    };

    #endif // POSITION_H

Position.cpp file: Position.cpp文件:

    #include "position.h"

    Position::Position()
    {
        m_Name = "";
        m_Description = "";
    }
    Position::Position(QString name, Qstring description)
    {
         m_Name = name;
         m_Description = description;
    }

    QString Position::toString()
    {
      return "";
    }

I have a main as well but it is not in use, i wanted to fix these problems before any more show up I've been looking this over and i cant seem to find out whats wrong, Please any help is greatly appreciated, Thank you in advance. 我也有一个主电源,但是它没有使用,我想在出现更多问题之前先解决这些问题,我一直在寻找这个问题,而且我似乎无法找出问题所在,请提供任何帮助,非常感谢,谢谢提前。

You have a circular dependency. 您具有循环依赖关系。 Person.h includes Employer.h which includes Person.h . Person.h包括Employer.h ,其中包括Person.h

You can forward declare Person in Employer.h : 您可以在Employer.h转发声明Person

Add class Person; 添加class Person; to Employee.h and move the #include "person.h" to Employee.cpp Employee.h并将#include "person.h"移到Employee.cpp

What the error comes from is when the compiler goes to compile Employer.cpp (or Person.cpp it doesn't matter which one), it includes the Employer.h , which tells the compiler to include Person.h , which tells the compiler to include Employer.h , but this time the include guards kick in and it stops the contents of Employer.h being included again. 错误的出处是当编译器去编译Employer.cpp (或Person.cpp无关紧要)时,它包含Employer.h ,它告诉编译器包括Person.h ,后者告诉编译器。包括Employer.h ,但这一次包括include防护,这将阻止再次包含Employer.h的内容。 So it starts to compile Person.h with no mention of Employer . 因此它开始编译Person.h ,而没有提到Employer Therefore it is an unknown type when it sees Employer m_employer . 因此,当它看到Employer m_employer时,它是一个未知类型。

暂无
暂无

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

相关问题 错误C2146:语法错误:缺少&#39;;&#39; 在标识符之前 - error C2146: syntax error : missing ';' before identifier 错误C2146:语法错误:在标识符&#39;A1&#39;之前缺少&#39;,&#39; - Error C2146: syntax error : missing ',' before identifier 'A1' 错误C2146:语法错误:缺少&#39;;&#39; 在标识符之前 - Error C2146: syntax error : missing ';' before identifier 错误C2146:语法错误:缺少&#39;;&#39; 在标识符&#39;ContextRecord&#39;之前 - error C2146: syntax error : missing ';' before identifier 'ContextRecord' 错误C2146:语法错误:缺少&#39;;&#39; 在标识符&#39;m_ball&#39;C ++之前 - error C2146: syntax error : missing ';' before identifier 'm_ball' C++, MFC 模板Fn指针错误C2146:语法错误:缺少&#39;;&#39; 在标识符之前 - Template Fn Pointer error C2146: syntax error : missing ';' before identifier 错误C2146:语法错误:在按功能传递地图时,在标识符mType之前缺少',' - error C2146: syntax error : missing ',' before identifier mType when passing a map by function C ++错误1错误C2146:语法错误:缺少&#39;;&#39; 在标识符“记录”之前 - C++ Error 1 error C2146: syntax error: missing ';' before identifier 'records' VC ++错误C2146:语法错误:标识符&#39;pFirst&#39;之前缺少&#39;)&#39; - VC++ error C2146: syntax error : missing ')' before identifier 'pFirst' 错误C2146:语法错误:缺少&#39;;&#39; 在标识符“ g_App”之前 - error C2146: syntax error : missing ';' before identifier 'g_App'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM