Click here to Skip to main content
15,907,231 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
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 
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 
I recommend you use a smart pointer like the following:
http://code.axter.com/clone_ptr.h

The above smart pointer has operator==() functions that work on the object itself instead of the pointer.

Example code:

#include <iostream><br />
#include <list><br />
#include "clone_ptr.h"<br />
<br />
using namespace std;<br />
<br />
class A<br />
{<br />
public:<br />
	A(int a) : m_a(a) {}<br />
	virtual ~A() {}<br />
	virtual void Somefunction() const<br />
	{<br />
		cout << "I'm A " << m_a << endl;<br />
	}<br />
	bool operator==(const A& Src)const{return (m_a == Src.m_a);}<br />
	int m_a;<br />
};<br />
<br />
class B : public A<br />
{<br />
public:<br />
	B(int a) : A(a) {}<br />
	void Somefunction() const<br />
	{<br />
		cout << "I'm B " << m_a << endl;<br />
	}<br />
};<br />
<br />
class C : public A<br />
{<br />
public:<br />
	C(int a) : A(a) {}<br />
	void Somefunction() const<br />
	{<br />
		cout << "I'm C " << m_a << endl;<br />
	}<br />
};<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
	list<clone_ptr<A> > MyListOfA_PtrsX;<br />
	MyListOfA_PtrsX.push_back(new A(1));<br />
	MyListOfA_PtrsX.push_back(new A(2));<br />
	MyListOfA_PtrsX.push_back(new A(3));<br />
	<br />
	list<clone_ptr<A> > MyListOfA_PtrsY;<br />
	MyListOfA_PtrsY.push_back(new B(4));<br />
	MyListOfA_PtrsY.push_back(new B(5));<br />
	MyListOfA_PtrsY.push_back(new B(6));<br />
	<br />
	list<clone_ptr<A> > MyListOfA_PtrsZ;<br />
	MyListOfA_PtrsZ.push_back(new C(1));<br />
	MyListOfA_PtrsZ.push_back(new C(2));<br />
	MyListOfA_PtrsZ.push_back(new C(3));<br />
<br />
	bool IsEqual1 = (MyListOfA_PtrsX == MyListOfA_PtrsY); //Should be false<br />
	bool IsEqual2 = (MyListOfA_PtrsX == MyListOfA_PtrsZ); //Should be true<br />
<br />
	cout << IsEqual1 << endl;<br />
	cout << IsEqual2 << endl;<br />
<br />
	system("pause");<br />
	return 0;<br />
}


Top ten member of C++ Expert Exchange.
http://www.experts-exchange.com/Cplusplus
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 
GeneralRe: handling WM_MOUSEWHEEL between two views Pin
Cedric Moonen4-Jul-05 23:13
Cedric Moonen4-Jul-05 23:13 
GeneralRe: handling WM_MOUSEWHEEL between two views Pin
Jörgen Sigvardsson6-Jul-05 1:01
Jörgen Sigvardsson6-Jul-05 1:01 
GeneralRe: handling WM_MOUSEWHEEL between two views Pin
Cedric Moonen6-Jul-05 4:00
Cedric Moonen6-Jul-05 4:00 
GeneralRe: handling WM_MOUSEWHEEL between two views Pin
Jörgen Sigvardsson6-Jul-05 1:08
Jörgen Sigvardsson6-Jul-05 1:08 
GeneralSorry! An error occured while generating the object Pin
AdyOS1-Jul-05 0:12
AdyOS1-Jul-05 0:12 

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.