Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class A { // Contained class.
- public:
- A(int i) : a_number_(i) {}
- void print() const { std::cout << a_number_ << "n"; }
- private:
- int a_number_;
- };
- class A_Container { // Container class.
- public:
- ~A_Container() { delete a_; }
- A_Container(const A& a) : a_(new A(a)) { std::cout << "I was called!n"; }
- const A& getA() const { return *a_; }
- private:
- A* a_;
- };
- void foo(const A_Container& container) { // This func takes a container...
- container.getA().print();
- }
- int main() {
- A a(147);
- foo(a); // ...but I'm passing it the contained class.
- return 0;
- }
- I was called!
- 147
Add Comment
Please, Sign In to add comment