CClass obj; //вызываем первый конструктор
obj = 1; // оператор присваивания
CClass obj2 = obj; // Конструктор копирования
#include <iostream>
using namespace std;
class A
{
int myint;
public:
A():myint(0)
{
cout<< this << " A():myint(0) myint == "<<myint<<endl;
}
A(int i):myint(i)
{
cout<< this << " A(int i):myint(i) myint == "<<myint<<endl;
}
~A()
{
cout<< this << " delete A()"<<endl;
}
};
int main()
{
A a;
a = 2;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class Foo
{
private:
string m_name;
const string m_name_on_born;
public:
Foo (const string &name): m_name(name), m_name_on_born(name) {
cout <<"Hi! I am " << m_name << endl;
}
~Foo() {
cout << m_name << " (on born be " << m_name_on_born << ") be destructed" << endl;
};
Foo& operator=(const Foo &other) {
cout <<"Hi! I am " << m_name << ". ";
cout << "But i be renamed to " << other.m_name << endl;
m_name = other.m_name;
return *this;
}
};
int main(int argc, char const *argv[])
{
Foo foo("foo");
foo = string("tmp");
return 0;
}
2) это не 1 а вертикальный слеш