Ray Devore wrote:
> 
>  > > Samp obj = Samp(12,22) // Explicit Call
> Calls constructor (not copy constructor) for
> Samp(12,22) and creates a temp object, then calls copy
> constructor to create and initialize obj with the temp
> object, then calls the destructor to delete the temp
> object so you get two additional function calls with
> the second method.

I wrote a sample program to check if the copy constructor would be 
called for the above statement.  But no copy constructor gets called. 
So I think there is no difference between the following two statements.

Type obj(p);
Type obj = p;

Here is the sample program.

(begin-code)

#include <iostream>
#include <string>

using namespace std;

class T
{
public:
    T(const string& n): name(n) {
       cout << "ctor: " << name << endl;
    }
    T(const T& that) {
       name = that.name;
       cout << "copy ctor: " << name << endl;
    }
    ~T() {
       cout << "dtor: " << name << endl;
    }
private:
    string name;
};

int main()
{
    T x("1");
    T y = T("2");
}

(end-code)

-- 
Always acknowledge a fault. This will throw those in authority off
their guard and give you an opportunity to commit more. - Mark Twain

Reply via email to