简体   繁体   English

C ++预期在'XY'之前的类型说明符-在成员函数virtual void中

[英]C++ Expected type-specifier before 'XY' - In member function virtual void

I work on my project (game in C++) and I found this error. 我在我的项目上工作(C ++游戏),发现此错误。

"Expected type-specifier before 'Clovek' In member function virtual void" “成员函数virtual void中'Clovek'之前的预期类型说明符”

This error is show for all - Clovek, PlatoveBrneni, ObourucniMec, BronzovyPrsten, LektvarCloveci. 此错误适用于所有用户-克洛维克,柏拉图·布尼尼,奥布鲁克尼·梅克,布朗佐维·普尔斯滕,列克瓦尔·克洛维奇。

For this project I use design pattern - builder. 对于这个项目,我使用设计模式-builder。

Thanks for all replies! 感谢您的所有回复!

Here are codes: 以下是代码:

CloverBuilder.h CloverBuilder.h

#ifndef CLOVEK_BUILDER_H
#define CLOVEK_BUILDER_H

#include <iostream>
#include "HrdinaBuilder.h"
#include "Rasa.h"
#include "Brneni.h"
#include "Zbran.h"
#include "Prsten.h"
#include "Lektvar.h"

using namespace std;

namespace LordOfDragonV2 {
    class ClovekBuilder : LordOfDragonV2::HrdinaBuilder {


    public:
        void buildRasa(string nazevRasy, int silaRasy, int odolnostRasy, int inteligenceRasy, int pocetZivotaRasy, string popisRasy);

        void buildBrneni(string nazevBrneni, int bonusOdolnosti, int bonusZivota);

        void buildZbran(string nazevZbrane, int bonusSily, int bonusZivota);

        void buildPrsten(string nazevPrstenu, int bonusInteligence, int bonusZivota);

        void buildLektvar(string nazevLektvaru, int bonusSily, int bonusOdolnosti, int bonusInteligence, int bonusZivota);
    };
}

#endif //CLOVEK_BUILDER_H

ClovekBuilder.cpp ClovekBuilder.cpp

#include "ClovekBuilder.h"

void LordOfDragonV2::ClovekBuilder::buildRasa(string nazevRasy, int silaRasy, int odolnostRasy, int inteligenceRasy, int pocetZivotaRasy, string popisRasy) {
    m_hrdina->setRasa( new Clovek(nazevRasy, silaRasy, odolnostRasy, inteligenceRasy, pocetZivotaRasy, popisRasy) );
}

void LordOfDragonV2::ClovekBuilder::buildBrneni(string nazevBrneni, int bonusOdolnosti, int bonusZivota) {
    m_hrdina->setBrneni(new PlatoveBrneni(nazevBrneni, bonusOdolnosti, bonusZivota));
}

void LordOfDragonV2::ClovekBuilder::buildZbran(string nazevZbrane, int bonusSily, int bonusZivota) {
    m_hrdina->setZbran(new ObourucniMec(nazevZbrane, bonusSily, bonusZivota));
}

void LordOfDragonV2::ClovekBuilder::buildPrsten(string nazevPrstenu, int bonusInteligence, int bonusZivota) {
    m_hrdina->setPrsten(new BronzovyPrsten(nazevPrstenu, bonusInteligence, bonusZivota));
}

void LordOfDragonV2::ClovekBuilder::buildLektvar(string nazevLektvaru, int bonusSily, int bonusOdolnosti, int bonusInteligence, int bonusZivota) {
    m_hrdina->pridejLektvar(new LektvarCloveci(nazevLektvaru, bonusSily, bonusOdolnosti, bonusInteligence, bonusZivota));
}

You did not show where Clovek is declared. 您没有显示Clovek的声明位置。 It is obvious that the compiler also does not see the corresponding declaration (and definition) of Clovek 显然,编译器也看不到Clovek的相应声明(和定义)。

You should include the header where this type is declared or/and defined. 您应该在声明或/和定义此类型的标头中包含标头。

For excample in this function you are trying to create an object of type Clovek using operator new: 以该函数为例,您尝试使用运算符new创建Clovek类型的对象:

void LordOfDragonV2::ClovekBuilder::buildRasa(string nazevRasy, int silaRasy, int odolnostRasy, int inteligenceRasy, int pocetZivotaRasy, string popisRasy) {
    m_hrdina->setRasa( new Clovek(nazevRasy, silaRasy, odolnostRasy, inteligenceRasy, pocetZivotaRasy, popisRasy) );

} }

Or maybe you need to use a qualified name for example LordOfDragonV2::Clovek instead of Clovek 或者,您可能需要使用限定名称,例如LordOfDragonV2 :: Clovek而不是Clovek

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

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