[英]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.