Click here to Skip to main content
15,903,388 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
Question[newbie] subclass std::list? Pin
ehh8-Jul-05 4:08
ehh8-Jul-05 4:08 
AnswerRe: [newbie] subclass std::list? Pin
Stuart Dootson8-Jul-05 7:48
professionalStuart Dootson8-Jul-05 7:48 
QuestionCOPY question??? Pin
Melena7-Jul-05 6:49
Melena7-Jul-05 6:49 
AnswerRe: COPY question??? Pin
Michael Dunn8-Jul-05 18:53
sitebuilderMichael Dunn8-Jul-05 18:53 
GeneralRe: COPY question??? Pin
Melena11-Jul-05 5:59
Melena11-Jul-05 5:59 
GeneralRe: COPY question??? Pin
Melena13-Jul-05 5:39
Melena13-Jul-05 5:39 
GeneralRe: COPY question??? Pin
Michael Dunn14-Jul-05 2:59
sitebuilderMichael Dunn14-Jul-05 2:59 
GeneralComparing STL containers of pointers Pin
Rob Caldecott7-Jul-05 5:24
Rob Caldecott7-Jul-05 5:24 
If I have an STL container that contains objects, then I can compare them easily - for example:

class CMyClass
{
int m_n;
CMyClass(int n) : m_n(n) { }

bool operator==(const CMyClass& o) const
{
// User defined comparison operator here
}
};

...

vector<CMyClass> v1;
vector<CMyClass> v2;
v1.push_back(CMyClass(1234));
v2.push_back(CMyClass(1234));

if (v1 == v2) // Calls CMyClass operator==


However, I often use containers of pointers, and when I do, comparing two containers doesn't call the objects operator== function. For example:

class CMyClass
{
int m_n;
CMyClass(int n) : m_n(n) { }

bool operator==(const CMyClass& o) const
{
// User defined comparison operator here
}
};

...

vector<CMyClass*> v1;
vector<CMyClass*> v2;
v1.push_back(new CMyClass(1234));
v2.push_back(new CMyClass(1234));

if (v1 == v2) // Simply compares the value of each pointer, so not much use!


My question is - are there any operators I can overload to make the comparison work for containers of pointers, or do I need to hand-roll my own comparison function? I hope this makes sense!


The Rob Blog
GeneralRe: Comparing STL containers of pointers Pin
Rob Caldecott7-Jul-05 6:07
Rob Caldecott7-Jul-05 6:07 
GeneralOoops... Pin
Rob Caldecott7-Jul-05 6:33
Rob Caldecott7-Jul-05 6:33 
GeneralOoops... Pin
Jörgen Sigvardsson7-Jul-05 9:56
Jörgen Sigvardsson7-Jul-05 9:56 
GeneralRe: Comparing STL containers of pointers Pin
Stuart Dootson8-Jul-05 7:45
professionalStuart Dootson8-Jul-05 7:45 
GeneralRe: Comparing STL containers of pointers Pin
Axter4-Aug-05 18:28
professionalAxter4-Aug-05 18:28 
Generaldueto Pin
Raudel6-Jul-05 5:49
Raudel6-Jul-05 5:49 
GeneralInitializing STL containers Pin
Rob Caldecott6-Jul-05 5:22
Rob Caldecott6-Jul-05 5:22 
GeneralRe: Initializing STL containers Pin
Michael Dunn6-Jul-05 6:31
sitebuilderMichael Dunn6-Jul-05 6:31 
GeneralRe: Initializing STL containers Pin
Rob Caldecott6-Jul-05 6:39
Rob Caldecott6-Jul-05 6:39 
GeneralRe: Initializing STL containers Pin
Rob Caldecott6-Jul-05 6:41
Rob Caldecott6-Jul-05 6:41 
Generalfind_if and function objects ('functors') Pin
Rob Caldecott5-Jul-05 3:11
Rob Caldecott5-Jul-05 3:11 
GeneralRe: find_if and function objects ('functors') Pin
Michael Dunn5-Jul-05 6:54
sitebuilderMichael Dunn5-Jul-05 6:54 
GeneralRe: find_if and function objects ('functors') Pin
Rob Caldecott5-Jul-05 22:48
Rob Caldecott5-Jul-05 22:48 
GeneralRe: find_if and function objects ('functors') Pin
Jörgen Sigvardsson5-Jul-05 12:37
Jörgen Sigvardsson5-Jul-05 12:37 
GeneralRe: find_if and function objects ('functors') Pin
Rob Caldecott6-Jul-05 0:21
Rob Caldecott6-Jul-05 0:21 
GeneralMFC events, in ATL with MFC support controls Pin
greekgoddj4-Jul-05 22:01
greekgoddj4-Jul-05 22:01 
Generalhandling WM_MOUSEWHEEL between two views Pin
retro_coder4-Jul-05 1:01
retro_coder4-Jul-05 1:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.