------------------------------------------------------------------------------
MC logo
C++ Translation of Java Dyn Link
[^] Functions
------------------------------------------------------------------------------
[Ch. 1: Overview and History] [Syntax] [Names and Scope] [Types and Type Systems] [Semantics] [Functions] [Memory Management] [Imperitive Programs and Functional Abstraction] [Modular and Class Abstraction] [Functional Programming] [Logic Programming]
[Call-by-Reference] [Call-by-Value-Result] [Call-by-Name] [Dyn Link Example] [Dyn Link Example] [C++ Translation of Java Dyn Link] [Variable Location] [Parameter Passing Method Exercise]
callex.cpp
#include <iostream>

using std::cout;
using std::endl;

class Stuff {
private:
        int a, b;

        int fred(int b) {
                a = a + b;
                return 4;
        }

        class Barney {
        private:
                int a;
                Stuff *dad;
                void sigfreid() {
                        a = dad->fred(a);
                }
        public:
                Barney(Stuff *_dad) { dad = _dad; }

                void barney(int c) {
                        a = c;
                        sigfreid();
                        cout << a << " " << dad->b << " " << c << endl;
                }
        };
public:
        Stuff() {
                a = 2;
                b = 7;
                Barney barn(this);
                barn.barney(3);
                cout << a << " " << b << endl;
        }
};

int main(int argc, char **argv)
{
        Stuff s;
}