简体   繁体   中英

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

I work on my project (game in C++) and I found this error.

"Expected type-specifier before 'Clovek' In member function virtual void"

This error is show for all - Clovek, PlatoveBrneni, ObourucniMec, BronzovyPrsten, LektvarCloveci.

For this project I use design pattern - builder.

Thanks for all replies!

Here are codes:

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

#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. It is obvious that the compiler also does not see the corresponding declaration (and definition) of 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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