au milieu des tests d'heritance de classe

This commit is contained in:
Hugo LAMY
2022-02-20 19:42:37 +01:00
parent 7e65467a27
commit 8918b348e0
10 changed files with 188 additions and 26 deletions

View File

@@ -0,0 +1,41 @@
#include "Base.hpp"
/*
* default/parametric constructor
*/
Base::Base( void ) {
std::cout << "base default constructor\n";
return;
}
/*
* destructor
*/
Base::~Base( void ) {
return;
}
/*
* copy constructor
*/
Base::Base( Base const & src ) {
std::cout << "base copy constructor\n";
*this = src;
return;
}
/*
* assignement operator
*/
Base & Base::operator=( Base const & rhs ) {
std::cout << "base assignations operator\n";
return *this;
}
Base::Base(int i) {
std::cout << "base parameters constructor\n";
}

View File

@@ -0,0 +1,19 @@
#ifndef BASE_HPP
# define BASE_HPP
#include <iostream>
class Base {
public:
Base( void ); // default/parametric constructor
Base( Base const & src ); // copy constructor
~Base( void ); // destructor
Base & operator=( Base const & rhs ); // assignement operator
Base(int i);
};
#endif

BIN
d03/test_inheritance/a.out Executable file

Binary file not shown.

View File

@@ -0,0 +1,39 @@
#include <iostream>
class Base {
public:
Base() {
std::cout << "base default constructor\n";}
Base(int i) {
std::cout << "base parameters constructor\n";}
Base(Base const & src) {
std::cout << "base copy constructor\n"; *this = src;}
Base & operator=(Base const & rhs) {
std::cout << "base assignation operator\n"; return *this;}
~Base() {
std::cout << "base default destructor\n";}
};
class Derived : public Base {
public:
Derived() {
std::cout << "derived default constructor\n";}
Derived(int i) {
std::cout << "derived parameters constructor\n";}
Derived(Derived const & src) {
std::cout << "derived copy constructor\n"; *this = src;}
Derived & operator=(Derived const & rhs) {
std::cout << "derived assignation operator\n"; return *this;}
~Derived() {
std::cout << "derived default destructor\n";}
};
int main () {
Base base1(1); std::cout << "\n";
Derived derived1(1); std::cout << "\n";
Base base2(derived1); std::cout << "\n";
Derived derived2(base1);
return 0;
}