Re: constructor and destructor when initializing sized vector
From: jjleto (jjleto_at_laposte.net)
Date: 11/12/04
- Next message: John Harrison: "Re: templated data member"
- Previous message: John Harrison: "Re: How do you pass a Vector to a function?"
- In reply to: Ron Natalie: "Re: constructor and destructor when initializing sized vector"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 12 Nov 2004 22:15:15 +0100
Ron Natalie a écrit :
> jjleto wrote:
>
>> When I run this simple program:
>>
>> #include <vector>
>> #include <iostream>
>> using namespace std;
>>
>> class A {
>> public:
>> A() { cout << "[ctor]" << endl; }
>> ~A() { cout << "[dtor]" << endl; }
>
> Add:
> A(const A&) { cout << "[copy ctor]" << endl; }
> A& operator=(const A&) { cout << "[op=]" <<endl; return *this; }
>
>> int main()
>> {
>> vector<A> v(3)
>
>
> The constructor you are using above has a second defaulted argument
> which is the value to fill the vector with. It is defaulted to a default
> constructoed A object.
>
> So you get:
> ctor - default constructed object for second constructor parameter
> copy ctor - v[0] being filled
> copy ctor - v[1] being filled
> copy ctor - v[2] being filled.
Thanks. It is clear now.
- Next message: John Harrison: "Re: templated data member"
- Previous message: John Harrison: "Re: How do you pass a Vector to a function?"
- In reply to: Ron Natalie: "Re: constructor and destructor when initializing sized vector"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|