T
Timothee Groleau
Hi all,
My name is Tim, I'm just getting started with C++ and this is my first post
to the group.
Is there a standard recommended approach to use a vector of pointers along
with <algorithm>?
To be specific, here is my situation, I have 2 classes A and B. Class A
contains a private vector of pointers to B objects and I need to sort this
vector after it is populated.
I was hoping to use <algorithm> sort along with an overloaded operator<
member function in B but that doesn't work with a vector of pointer.
Is it better to create a global compare function that deferences the
pointers or to create a static compare function in class A instead (since
the sorting will be done by class A only)?
I did some research and I also found this ptr_vector template:
http://www.codeproject.com/vcpp/stl/ptr_vecto.asp
which looks like it may do just what I need. Has anybody tried successfully
a similar approach before?
Thanks in advance!
Tim.
My name is Tim, I'm just getting started with C++ and this is my first post
to the group.
Is there a standard recommended approach to use a vector of pointers along
with <algorithm>?
To be specific, here is my situation, I have 2 classes A and B. Class A
contains a private vector of pointers to B objects and I need to sort this
vector after it is populated.
I was hoping to use <algorithm> sort along with an overloaded operator<
member function in B but that doesn't work with a vector of pointer.
Is it better to create a global compare function that deferences the
pointers or to create a static compare function in class A instead (since
the sorting will be done by class A only)?
I did some research and I also found this ptr_vector template:
http://www.codeproject.com/vcpp/stl/ptr_vecto.asp
which looks like it may do just what I need. Has anybody tried successfully
a similar approach before?
Thanks in advance!
Tim.