Click here to Skip to main content
15,909,445 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a class EscapeRoomWrapper now i made another two classes which are the "sons" of this class ScaryRoom and KidsRoom , which means ScaryRoom is a EscapeRoomWrapper and KidsRoom is a EscapeRoomWrapper , now for each one of those classes i wrote functions ..

i am working now from another class which is company , and in this class i added a set of all the rooms (EscapeRoomWrapper,ScaryRoom,KidsRoom) now i want to write a function in class company that i give it a type of room and it should returns for me all of the rooms from that type that exists in the victor of all rooms , then i thougt about using typeid but then the professer banned us from using it , my last idea is to use cast dynamic 
<pre>any ideas of how i can do this function ?? <pre>std::vector<EscapeRoomWrapper*>& getAllRoomsByType(RoomType type) const
.

What I have tried:

public:
// functions here
};

private:
int a
public:
// functions for y room
};

class : public {
Posted
Updated 5-Jul-17 21:07pm
v2

1 solution

If EscapeRoomWrapper has a RoomType member then it knows what type each derived object is and it can use that with dynamic_cast. If the called methods are the same for each derivation then you won't need to cast.
 
Share this answer
 
Comments
Learnignc 28-Jun-17 8:42am    
i actually knew how to do it ,, and did it with dynamic cast at the end

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900