CLASS AND VECTOR

Hi . I Need some Information about how too assigne a class to a vector

class A
{
protected:
string name;
};
class B : public A
{
private:
int ID_B;
}
class C : public A
{
private:
int ID_B;
B bb;

}

how to assgine a class to vector .
which refrences can I find to reading ?
What do you mean, assign?
to put something into a vector write:
1
2
3
std::vector<MyClass> my_vector;
MyClass mc;
my_vector.push_back(mc);

Here it doesn't matter what you write Instead of MyClass. It could be int, std::string, A, B or A* or anything else...
If you want to be able to push A B and C, you'll have to use polymorphism.
1
2
std::vector<BaseClass*> my_vector;
my_vector.push_back(new DerivedClass);

Here BaseClass is A and DerivedClass could be B or C.
thanks .
how can Update when i change attribute (ID_B) . this attribute changes in Class C ;

( class C has a Attribute from class B )

thanks again.

Additionally, be sure to delete any memory allocated with operator new.
Topic archived. No new replies allowed.