'C++ How to iterate over template vector
I have this vector:
std::vector<D*> _database;
typename D is representing this struct:
struct GameObjectsDatabaseContainer : GameDatabaseContainer
{
public:
std::string name;
std::string prefab;
};
And this function:
template<typename T, typename D>
std::vector<D *> GameDatabase<T, D>::GetDatabase() {
return this->_database;
}
This is how I add data to the vector:
template<typename T,typename D>
void GameDatabase<T,D>::PopulateDatabase(D* gdc)
{
_database.push_back(gdc);
}
And here is how I try to iterate over my template vector:
for(typename std::vector<D>::iterator iter = this->GetDatabase().begin(); iter != this->GetDatabase().end(); iter++)
{
std::cout << (*iter)->name << std::endl;
}
Note that this iteration is happening in a child class which is passing GameObjectsDatabaseContainer as typename D
I am trying to reach (*iter)->name because inside GameObjectsDatabaseContainer I have a member name.
However this is not working. How can I iterate over template vector and display properly it's content ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
