I would like to have objects add a pointer pointing to themselves into a map which is a member of another class.
Here is what I have so far:
Код: Выделить всё
//entitymanager.h
//inside the public part of the entitymanager class
std::map AllMapEntities;
//in main.cpp
EntityManager.AllMapEntities.insert({ 1, pObject1});
//in mapentity.cpp
//constructor for mapentity
MapEntity::MapEntity(){
EntityManager.AllMapEntities.insert({ meid, this });
}
However if I try to have the object add the pointer during its construction then it fails.
In mapentity.cpp - The errors are at the dot and at the first curly bracket and the errors are "expected an identifier" and "expected a type specifier".
I don't see why the same syntax would work if called in main.ccp however it would not work in the constructor.
Источник: https://stackoverflow.com/questions/781 ... onstructor
Мобильная версия