[ create a new paste ] login | about

Link: http://codepad.org/UAaW91DG    [ raw code | output | fork ]

C++, pasted on Feb 26:
#include<iostream>

#ifndef __FOO_H_INCLUDE
    #define __FOO_H_INCLUDE
    #ifndef __FOO_H_DEFINED
        #define __FOO_H_DEFINED
        class foo;
        #ifndef __BAR_H_INCLUDE
            #define __BAR_H_INCLUDE
            #ifndef __BAR_H_DEFINED
                #define __BAR_H_DEFINED
                class bar;
            #endif
            class bar{
                foo *a;
                int b;
                public:
                bar(int _b );
                foo& getfoo();
                int getb();
                void setfoo( foo* _a );
            };
        #endif
    #endif
    class foo{
        bar *a;
        int b;
        public:
        foo( int _b );
        bar& getbar();
        int getb();
        void setbar( bar* _a );
    };
#endif


foo::foo( int _b ){ b = _b;}
int foo::getb(){ return b; }
bar& foo::getbar(){ return *a; }
void foo::setbar( bar* _a){ a = _a; }

bar::bar( int _b ){ b = _b;}
int bar::getb(){ return b; }
foo& bar::getfoo(){ return *a; }
void bar::setfoo( foo* _a ){ a = _a; }



int main(){
    foo a(5);
    bar b(20);
    a.setbar(&b);
    b.setfoo(&a);
    std::cout   << a.getbar().getfoo().getbar().getb() 
                << "\n" 
                << a.getbar().getfoo().getbar().getfoo().getb();
    return 0;
}


Output:
1
2
20
5


Create a new paste based on this one


Comments: