Неполные типы с++

#include<iostream>
#include<vector>
using namespace std;
class Hero {

protected:
    int b;
public:
    virtual void logic(int a) {
        b = a;
        cout << "hero" << ++a;
    }
    virtual char type() { return 'h'; }
};

class Bad :public Hero
{
private:
    Object* obj;
public:
    template<class T>
    void set(Game* g) {
        obj = new T();
        obj->set(g);
    }
    void logic() { obj->logic(); }
    char type() { return 'b'; }
};

class Object
{
    Game* game;
public:
    virtual void set(Game* g) { game = g; }
    virtual void logic() { cout << "in"; }

};


class Game {
public:
    Storage str;

};
class Storage
{
    vector<Hero*> heroes;
public:
    template<class T>
    void add_hero() {
        heroes.push_back(new T());
    }

    template<class T>
    T& get() {
        for (auto& hero : heroes) {
            if (typeid(*hero) == typeid(T))
                return static_cast<T&>(*hero);
        }
    }
    
};

int main() {
    Game g;
    g.str.add_hero<Bad>();
    g.str.get<Bad>().set<Object>(&g);
    g.str.get<Bad>().logic();
    return 0;
}

вот ошибка ошибка

как пофиксить P.S максимально ужал код ибо в проекте еще больше указателей


Ответы (1 шт):

Автор решения: timafaer

понял что ошибка в последовательности объявлении классов

#include<iostream>
#include<vector>
using namespace std;
class Hero {

protected:
    int b;
public:
    virtual void logic(int a) {
        b = a;
        cout << "hero" << ++a;
    }
    virtual char type() { return 'h'; }
};


class Storage
{
    vector<Hero*> heroes;
public:
    template<class T>
    void add_hero() {
        heroes.push_back(new T());
    }

    template<class T>
    T& get() {
        for (auto& hero : heroes) {
            if (typeid(*hero) == typeid(T))
                return static_cast<T&>(*hero);
        }
    }

};


class Game {
public:
    Storage str;

};


class Object
{
    Game* game;
public:
    virtual void set(Game* g) { game = g; }
    virtual void logic() { cout << "in"; }

};



class Bad :public Hero
{
private:
    Object* obj;
public:
    template<class T>
    void set(Game* g) {
        obj = new T();
        obj->set(g);
    }
    void logic() { obj->logic(); }
    char type() { return 'b'; }
};


int main() {
    Game g;
    g.str.add_hero<Bad>();
    g.str.get<Bad>().set<Object>(&g);
    g.str.get<Bad>().logic();
    return 0;
}
→ Ссылка