I'm making a tower defense game by using c++ & sfml. I have the classes (object, Tower, Enemy), The classes Tower and Enemy inherite class object;
see this code:
int main()
{
std::list<object*> Objects;
.....
while(window.isOpen())
{
.......
for(auto a:Objects)
{
for(auto b:Objects)
{
if(a != b && a->name == "tower" && b->name == "enemy" && distance(a, b) <= a->range)
{
a->targets.push_back(b); // here's the problem, when i compile it i get:
} // error: 'class object' has no member named 'targets'
}
}
}
}
My problem is:
class 'Tower' has member 'targets' which is 'list' and because 'Tower' inherite 'object' so i can add it's pointer to list 'objects', I can edit 'x, y, name' but i can't edit the members in 'Tower' as the compiler told (error: 'class object' has no member named 'targets').
What is the solution?