6
I have the following problem, as 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 ;
}
When compiling it shows the error "error: use of Deleted Function", because when returning the object c this no longer exists.
How can I get around such a situation, knowing I have to return to the class To the modified object of the class C and that the only function in the class C must be of the void type.
It would already help a way to read the variable d (date member) of the class C in class To
I was really unhappy in transforming a very complex code, in a didactic example (as described), to exemplify the compilation error, but this code does not compile in the Linux platform, because the C class is destroyed before it passes, therefore of the described error. What I intend to receive is the object of class C (which has been modified) in class A.
– Morse
I can only answer what is in the question and showed that taking out the syntax errors compiles. More than that I could not do. If you have other problems ask a new question, this time ask a [mcve].
– Maniero
I made some modifications to the original code. So I can access the date int d member of class C from class A.
– Morse
@Morse you have to ask another question, that, as you posted, was answered. See the [tour] and the [Ask].
– Maniero