d04 ex01 ok change affichage + delete brain + constructors with default arguments

This commit is contained in:
hugogogo
2022-02-26 19:20:49 +01:00
parent 12f4c72e77
commit ed2bbc7fd2
8 changed files with 116 additions and 29 deletions

43
d04/ex01/test.cpp Normal file
View File

@@ -0,0 +1,43 @@
#include <iostream>
class A {
public:
A & operator=( A const & rhs ) {
std::cout << "A assignation operator\n";
_i = rhs._i;
return *this;}
private:
int _i;
};
class B {
public:
B() {
std::cout << "B default constructor\n";
_a = new A();}
B( A *a ) {
std::cout << "B parameterized constructor\n";
_a = new A();
*_a = *a;}
~B() {
std::cout << "B destructor\n";
delete _a;}
private:
A *_a;
};
int main() {
{
const B * b = new B();
delete b;
}
std::cout << "\n";
{
B * b;
A * a = new A();
b = new B(a);
delete a;
delete b;
}
return 0;
}