diff options
Diffstat (limited to 'class_ref.cpp')
-rw-r--r-- | class_ref.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/class_ref.cpp b/class_ref.cpp new file mode 100644 index 0000000..179c967 --- /dev/null +++ b/class_ref.cpp @@ -0,0 +1,59 @@ +#include <iostream> +#include <cstdlib> + +class Drink +{ + public: + Drink(int cost) + { + this->cost = cost; + } + + + int get_cost(void); + + private: + + protected: + int cost; +}; + +int Drink::get_cost(void) +{ + return cost; +} + +class Juice : public Drink +{ + public: + Juice(int shelf, int cost) : Drink(cost), shelf(shelf) + { + std::cout << "got called\n"; + } + + int get_shelf(void); + + private: + int shelf; + + protected: +}; + +int Juice::get_shelf(void) +{ + return shelf; +} + +int main(int argc, char **argv) +{ + Juice *dubjuice = new Juice(1, 5); + std::cout << dubjuice->get_cost() << std::endl; + std::cout << dubjuice->get_shelf() << std::endl; + + Juice ref = *dubjuice; + std::cout << ref.get_cost() << std::endl; + std::cout << ref.get_shelf() << std::endl; + + return 0; +} + |