From f6d9636caa9123a075b7f4d580975eb6855c8307 Mon Sep 17 00:00:00 2001 From: neingeist Date: Fri, 18 Apr 2014 19:26:02 +0200 Subject: [PATCH] add a copy and a "normal" constructor --- classes.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/classes.cpp b/classes.cpp index 3da15b0..89059c1 100644 --- a/classes.cpp +++ b/classes.cpp @@ -3,6 +3,13 @@ class Animal { public: + Animal() { + std::cout << "constructor" << std::endl; + } + Animal(const Animal& other) { + std::cout << "copy constructor" << std::endl; + } + // Note: using *virtual* does the difference here! virtual void makeSound() const { std::cout << " from " << this << std::endl; @@ -49,16 +56,21 @@ int main() { std::cout << "== Some animals" << std::endl; Animal animal; animal.makeSound(); + + std::cout << "== animal" << std::endl; call(animal); callref(animal); callptr(&animal); + std::cout << "== cat" << std::endl; animal = cat; // <- lol, operator animal.makeSound(); call(cat); callref(cat); // <- meow + callref(animal); // <- generic callptr(&cat); // <- meow + std::cout << "== cow" << std::endl; animal = cow; // <- lol, operator animal.makeSound(); call(cow);