   Need clever solution
  Hi,I could not find any suitable solution, I hope someone clever will...class A : public C{public: int _a;};class B : public C{public:char _b;};I have two class with different members. I want to store A and B on vector.Is there a way (beside "dynamic_cast<>" vec[index] ) to access the class members from the vector?   
  Don't think theres a solution for getting around this, just variations of the same thing really. One way would be to do your own rtti:class C{public:virtual Type GetType() = 0;}class A : public C{public: virtual Type GetType() { return Type_A; }int _a;};class B : public C{public:virtual Type GetType() { return Type_B; }char _b;};C *object = .....;switch(object->GetType()){case Type_A:{A *temp = dynamic_cast<A*>(object);....}break;}Your still doing the same thing but I beleive its faster that using dynamic cast to discover the correct type. (You'll still have to dynamic_cast eventually anyway, you could c style cast).   ;  Assuming the class members you want to access are delcared in class "C", then yes.  The source code below is valid as long as 'DoSomething()' is a function declared in "C" (and possibly over-ridden in "A" and "B").std::vector<C*> objects;objects.push_back(new A);objects.push_back(new B);objects[0]->DoSomething();objects[1]->DoSomething();Assuming the class members you want to access are only declared in "A" and "B", then no, you need to go the dynamic_cast<>() route.What exactly is it you are trying to do?  Giving some background may produce better answers to your question.   ;  What about the performances? does dynamic_cast impact the speed?If real time is a must, is it good thing to do dynamic_cast every frame?   ;Quote:Original post by masterbubuWhat about the performances? does dynamic_cast impact the speed?If real time is a must, is it good thing to do dynamic_cast every frame?Depends.  How many casts a second are you doing?  Better yet, what is it that you are trying to do?   ;Quote:I have two class with different members. I want to store A and B on vector.Then you're doing it wrong. What is your actual problem that you're trying to solve?   ;  I'm trying to create new shaders system.The current state:I have a wrapper class for each shader. then I use Update() to update the shader uniforms, before glDrawArrays() gets called.The current status wont allow me to update the shader whenever I want + The userdon't have full control on the shader.The new requirements:1. You can update the shader whenever you want. -> The wrapper class will have variable for each uniform. Update() will feed the uniform handles with class members.2. The user will only have access to the class member. It should not have any clue about the uniforms from GLSL. It only has to do shader-> and get the available members of the shader to manipulate.3. The user should have the ability to switch shaders whenever it wants.basically by wrapping up each shader, the user can use manipulate them and not care about the GLSL implementation. Two possible solutions:1. I can however do ugly thing: -> try to get handle for uniform variable. if it exist, good for me, else nothing will happen, and the variable will get the default 0 value. 2. Each shader will call to function pointer on Update(). this indeed solve the problem but it cause the user to create messy code.I almost found a solution ( Templates ) but the entire idea falls because each class has different members -> we need dynamic_cast and so on ...I'm might be locked on the above idea, can someone light may way? ;  I posted something in a similar thread a while back for a GLSL shader class, you might want to see if you can pick up any idea in there.  Thread;  Nice idea, but its not what I'm looking for   ;  Do a search for value_ptr. It will allow you to do what you want, complete with all the correct polymorphic behaviour etc.   