Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Trying to make an Entity that contains entities in it and draws them. Failing...  (Read 1358 times)

0 Members and 1 Guest are viewing this topic.

LightCancel

  • Newbie
  • *
  • Posts: 6
    • View Profile
Using the example from the vertex tutorial I made an object that can be draw. Right now I'm trying to make another object (here now called multi-object) that inherits from the initial object (here now called single-object)with its key feature being that it contains within it a map of pointers to other objects of the first variaty. So I try to overload to the draw function of multi-object but I run into the trouble that I can't iterate through the map to call draw on each one. Does anyone have any solutions.

To repeat:
-I have a single-object class modled after the myentity class from the vertext tutorial.
-I am making a multi-object class that inherits from single-object and contains a map of single objects.
-Trying to overload the draw func from single-object to draw every object within the map while still being able to be called like single-objects (window.draw(object), and failing horribly. Help, please!

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
There's no reason for the multi-object to inherit from the single-object.  If you get rid of that inheritance, you shouldn't have any problems.

Though if for some reason you really want the inheritance, draw() is (or should be) a virtual function, so it can have a completely different implementation in the subclass.

LightCancel

  • Newbie
  • *
  • Posts: 6
    • View Profile
draw is indeed a virtual func, but the problem I'm encountering it that the draw function must be const, and something about that seems to dissallow me from accessing map entires with the square-brackets.

MapAct["Entry"];

I get this error.

error C2678: binary '[' : no operator found which takes a left-hand operand of type 'const std::map<std::string,ActorC *,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>' (or there is no acceptable conversion)

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
That operator in std::map is not const so you can't call it on const variables, you should use find.
Back to C++ gamedev with SFML in May 2023

LightCancel

  • Newbie
  • *
  • Posts: 6
    • View Profile
Thanks. I'm kinda beside myself with how little I know, but I'm learning. Thanks a ton!