Return modified object

4

I have the following problem, according to the didactic example below:

    #include "b.h"
    #include "c.h"
    class A
    {
        public:
           int start();
        private:            
            B b;
            C c;
            int x;      


    }

    a.cpp

    int A::start()
    {
        c = b.copy();
        x = c.d;
        return x;
    }



    #include "c.h"
    class B
    {
        private:
            C c;        
        public:
            C copy();
    }

    b.cpp

    C B::copy()
    {
        c.add(1);   
        return c;
    }


    class C
    {           
        public:
            void add(int x);
            int d;
    }

    c.cpp

    void c.add(int x)
    {
        C::d = x + 10;
        return;
    }


    main()
   {   
      A a;
      int y;

      y = a.start();

      cout << y ;

   }

/ strong> this does not exist anymore.

How can I get around this situation, knowing that I have to return to the A class the modified object of the C and that the only function in the C class must be void.

It would already help a way to read the variable d (member date) of the C class in the A     

asked by anonymous 22.10.2016 / 23:43

1 answer

2

It has a lot of syntax errors there, too much typo. Programming is not playing any text and any way it will work. I made some modifications and at least compiled. I do not know if you do what you expect.

class C {
    private:
        int d;
    public:
        void add(int x);
};

void C::add(int x) {
    d = x + 10;
    return;
}

class B {
    private:
        C c;        
    public:
        C copy();
};

C B::copy() {
    c.add(1);   
    return c;
}

class A {
    private:
        void start();
        B b;
        C c;        
};

void A::start() {
    c = b.copy();
}

int main() {}

See compiling and running in ideone and in CodingGround .

    
22.10.2016 / 23:52