Midterm2-question 7 source code

22 views
Skip to first unread message

Hacer Keles

unread,
May 3, 2013, 12:33:17 PM5/3/13
to com...@googlegroups.com
#include <iostream>
using namespace std;

class A
{
string name;
public:
A(string n)
{
name = n;
cout<<"constructor: "<<name.c_str()<<endl;
}
A(const A& x)
{
name = x.name;
cout<<"copy constructor: "<<name.c_str()<<endl;
}
A& operator=(const A& x)
{
name = x.name;
cout<<"copy assignment: "<<name.c_str()<<endl;
return *this;
}
static A g(A x)
{
cout<<"in function g"<<endl;
A a("a");
return x;
}
};

int main()
{
A a1("a1");
A a2=a1;
A a3("a3");
a2 = a3;
A a4 = A::g(a2);
}

Reply all
Reply to author
Forward
0 new messages