R
Rusty
Is there any way to use the STL algorithm for_each if my container
contains pointers? For example,
class A
{
int a;
virtual void print (void) {cout << a << endl;}
};
class B: public A
{
int b;
virtual void print (void) {cout << a << "," << b << endl;}
}
I want to have a list that I can call print() on for each member, so I
figured vector <A*>. Is there anyway to get the following with
for_each?
vector <A*>::iterator i;
for (i=list.begin(); i<list.end(); ++i) (*i)->print();
Russ
contains pointers? For example,
class A
{
int a;
virtual void print (void) {cout << a << endl;}
};
class B: public A
{
int b;
virtual void print (void) {cout << a << "," << b << endl;}
}
I want to have a list that I can call print() on for each member, so I
figured vector <A*>. Is there anyway to get the following with
for_each?
vector <A*>::iterator i;
for (i=list.begin(); i<list.end(); ++i) (*i)->print();
Russ