Click here to Skip to main content
15,895,011 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Late binding on ATL COM dll Pin
HakunaMatada30-Mar-06 17:17
HakunaMatada30-Mar-06 17:17 
GeneralRe: Late binding on ATL COM dll Pin
Stephen Hewitt30-Mar-06 17:57
Stephen Hewitt30-Mar-06 17:57 
GeneralRe: Late binding on ATL COM dll Pin
Jörgen Sigvardsson30-Mar-06 20:13
Jörgen Sigvardsson30-Mar-06 20:13 
QuestionATL Dialogs Pin
Stober29-Mar-06 6:53
Stober29-Mar-06 6:53 
AnswerRe: ATL Dialogs Pin
Michael Dunn29-Mar-06 9:49
sitebuilderMichael Dunn29-Mar-06 9:49 
QuestionNested Objects Pin
zubair_ahmed28-Mar-06 21:55
zubair_ahmed28-Mar-06 21:55 
QuestionATL RichEdit Pin
Anilkumar K V28-Mar-06 16:26
Anilkumar K V28-Mar-06 16:26 
Questionhow does copy constructor works with vector::push_back Pin
Ajax9528-Mar-06 13:02
Ajax9528-Mar-06 13:02 
I'm trying to figure out how exactly vector::push_back() creates objects.
Looks like vector::push_back() will create a lot of copies by copy constructor and destruct a lot. In other words, if I need to put a counter in the copy constructor to monitor how many copy of the objects are created during the run, I will get a number which I don't exactly understand why. Can anybody explain why push_back() keep making copies and deleting copies?

By running the following sample program, I supose to get 2,4,6,8,10 as output, but I get 21,22,23,24,25. Why is that?

Thanks!

class CVecTest
{
public:
CVecTest() {m_intCount = ++m_classNumber;}
CVecTest::CVecTest(const CVecTest &vec) {m_intCount = ++m_classNumber;}
~CVecTest(){};
static int m_classNumber;
int m_intCount;
};

int CVecTest::m_classNumber = 0;

int main(int argc, char* argv[])
{
vector<cvectest> vec;

for (int i=0; i<5; i++)
{
CVecTest p;
vec.push_back(p);
}

for (int i=0; i<5; i++)
cout << vec[i].m_intCount << endl;

return 0;
}
Confused | :confused:
AnswerRe: how does copy constructor works with vector::push_back Pin
Stephen Hewitt28-Mar-06 15:20
Stephen Hewitt28-Mar-06 15:20 
GeneralRe: how does copy constructor works with vector::push_back Pin
Nemanja Trifunovic29-Mar-06 8:45
Nemanja Trifunovic29-Mar-06 8:45 
GeneralRe: how does copy constructor works with vector::push_back Pin
Stephen Hewitt29-Mar-06 11:14
Stephen Hewitt29-Mar-06 11:14 
AnswerRe: how does copy constructor works with vector::push_back Pin
Johann Gerell28-Mar-06 15:30
Johann Gerell28-Mar-06 15:30 
GeneralRe: how does copy constructor works with vector::push_back Pin
Ajax9528-Mar-06 17:11
Ajax9528-Mar-06 17:11 
GeneralRe: how does copy constructor works with vector::push_back Pin
Stephen Hewitt28-Mar-06 18:05
Stephen Hewitt28-Mar-06 18:05 
GeneralRe: how does copy constructor works with vector::push_back Pin
Ajax9528-Mar-06 20:06
Ajax9528-Mar-06 20:06 
GeneralRe: how does copy constructor works with vector::push_back Pin
Johann Gerell29-Mar-06 1:22
Johann Gerell29-Mar-06 1:22 
GeneralRe: how does copy constructor works with vector::push_back Pin
Johann Gerell29-Mar-06 1:20
Johann Gerell29-Mar-06 1:20 
AnswerRe: how does copy constructor works with vector::push_back Pin
Arvind Bharti30-Mar-06 15:54
Arvind Bharti30-Mar-06 15:54 
Questionatl com error Pin
_tasleem28-Mar-06 2:58
_tasleem28-Mar-06 2:58 
AnswerRe: atl com error Pin
toxcct28-Mar-06 3:05
toxcct28-Mar-06 3:05 
QuestionATL classes Pin
_tasleem27-Mar-06 23:58
_tasleem27-Mar-06 23:58 
AnswerRe: ATL classes Pin
toxcct28-Mar-06 0:36
toxcct28-Mar-06 0:36 
Questionatl+mfc Pin
_tasleem27-Mar-06 22:40
_tasleem27-Mar-06 22:40 
AnswerRe: atl+mfc Pin
toxcct27-Mar-06 23:11
toxcct27-Mar-06 23:11 
GeneralRe: atl+mfc Pin
_tasleem27-Mar-06 23:53
_tasleem27-Mar-06 23:53 

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.