'C++ trying to create of vector of child struct and iterate over it

I have the following:

std::vector<GameDatabaseContainer*> _database;

template<typename T>
void GameDatabase<T>::PopulateDatabase(GameDatabaseContainer* gdc)
{
    _database.push_back(gdc);
}

struct GameDatabaseContainer
{

};

struct GameObjectsDatabaseContainer : GameDatabaseContainer
{
    std::string name;
    std::string prefab;
};

And I have this function:

template<typename T>
void GameObjectsDatabase<T>::MapGameDatabaseContainer()
{
    PreparedQueryResult result = WorldDatabase.Query(this->_preparedStatement);

    if (result)
    {
        do {
            auto * godc = new GameObjectsDatabaseContainer();

            Field* fields = result->Fetch();
            auto name = fields[1].GetString();
            auto prefab = fields[2].GetString();
            godc->name = name;
            godc->prefab = prefab;
            this->PopulateDatabase(godc);

        } while (result->NextRow());
    }

    for(auto i = this->_database.begin(); i != this->_database.end(); i++)
    {
        std::cout << (*i)->name << (*i)->prefab << std::endl;

    }
    //std::cout << "SIZE: " << this->_database.size() << std::endl;

}

This function reads the database which have 2 records. If I run std::cout << "SIZE: " << this->_database.size() << std::endl; i see output SIZE: 2

However the code which I currently showing throws the following error:

In file included from /Users/venelin/Vibranium-Core/Source/Common/Database/GameDatabaseLoader.h:10,
                 from /Users/venelin/Vibranium-Core/Source/Common/Database/GameDatabaseLoader.cpp:5:
/Users/venelin/Vibranium-Core/Source/Common/Database/GameDatabaseImplementation/GameObjectsDatabase.h: In instantiation of 'void GameObjectsDatabase<T>::MapGameDatabaseContainer() [with T = WorldDatabaseConnection]':
/Users/venelin/Vibranium-Core/Source/Common/Database/GameDatabaseLoader.cpp:12:34:   required from here
/Users/venelin/Vibranium-Core/Source/Common/Database/GameDatabaseImplementation/GameObjectsDatabase.h:52:28: error: 'struct GameDatabaseContainer' has no member named 'name'
   52 |         std::cout << (*i)->name << (*i)->prefab << std::endl;
      |                      ~~~~~~^~~~
/Users/venelin/Vibranium-Core/Source/Common/Database/GameDatabaseImplementation/GameObjectsDatabase.h:52:42: error: 'struct GameDatabaseContainer' has no member named 'prefab'
   52 |         std::cout << (*i)->name << (*i)->prefab << std::endl;
      |                                    ~~~~~~^~~~~~
make[3]: *** [Source/Common/CMakeFiles/Common.dir/Database/GameDatabaseLoader.cpp.o] Error 1
make[2]: *** [Source/Common/CMakeFiles/Common.dir/all] Error 2
make[1]: *** [Source/WorldServer/CMakeFiles/WorldServer.dir/rule] Error 2
make: *** [WorldServer] Error 2

Looks like it is looking for member name in struct GameDatabaseContainer when I think it have to look for name inside GameObjectsDatabaseContainer which have such member.

Why am I getting this error and how can I fix it ?

c++


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source