Guest_imported
New member
- Jan 1, 1970
- 0
Last time i was wrong. i´ve made real example which gives me the problem that i wanted to ask you. i will tell you again about my doubt.
i have two classes (for example X and Y) and i need a method in each one which let me obtain an object from the other class. I´ve tested the next:
(see my explanation below)
file x.hpp------------------
#include <iostream.h>
#include "C:\__trabajo\prog\__cpp\clases\_pruebas\UTM\problema1\Y.hpp"
class Y;
class X
{
private:
int i;
public:
void toY(Y &y)
{
y.setJ(function(i));
}
int function(int val)
{
cout << "To Y" << endl;
return val*2; //really a more complex transformation
}
int getI() { return i; }
void setI(int i) { this.i=i; }
};
end of file x.hpp------------------
file y.hpp------------------
#include <iostream.h>
#include "C:\__trabajo\prog\__cpp\clases\_pruebas\UTM\problema1\X.hpp"
class X;
class Y
{
private:
int j;
public:
void toX(X &x)
{
x.setI(function(i));
}
int function(int val)
{
cout << "To X" << endl;
return val*4; //really a more complex transformation
}
int getJ() { return j; }
void setJ(int j) { this.j=j; }
};
end of file y.hpp------------------
file main.cpp------------------
#include "C:\__trabajo\prog\__cpp\clases\_pruebas\UTM\problema1\X.hpp"
#include "C:\__trabajo\prog\__cpp\clases\_pruebas\UTM\problema1\Y.hpp"
void main(void)
{
X ox;
Y oy;
ox.toY(oy); //ox change to oy
}
end of file main.cpp------------------
but in each file i´m including the class (file) that i want to get, so i get the compiling error:
--------------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
c:\__trabajo\prog\__cpp\clases\_pruebas\utm\problema1\x.hpp(2) : warning C4182: #include nesting level is 363 deep; possible infinite recursion
c:\__trabajo\prog\__cpp\clases\_pruebas\utm\problema1\x.hpp(2) : fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
Error executing cl.exe.
main.obj - 1 error(s), 1 warning(s)
i´ve put the title "OOP Probrem" because i think that is not a c++ error.
How can i make this work? As you see i want to use the take the private data of one of the classes, change it with an algoritmn and put the result in the private data of the other class. And the same in the opposite way.
I want to transform one class to the other one.
Maybe the only way is to use "friends". i ´d be very grateful if you can help me.
Anyway thank you for your patience.
bye
i have two classes (for example X and Y) and i need a method in each one which let me obtain an object from the other class. I´ve tested the next:
(see my explanation below)
file x.hpp------------------
#include <iostream.h>
#include "C:\__trabajo\prog\__cpp\clases\_pruebas\UTM\problema1\Y.hpp"
class Y;
class X
{
private:
int i;
public:
void toY(Y &y)
{
y.setJ(function(i));
}
int function(int val)
{
cout << "To Y" << endl;
return val*2; //really a more complex transformation
}
int getI() { return i; }
void setI(int i) { this.i=i; }
};
end of file x.hpp------------------
file y.hpp------------------
#include <iostream.h>
#include "C:\__trabajo\prog\__cpp\clases\_pruebas\UTM\problema1\X.hpp"
class X;
class Y
{
private:
int j;
public:
void toX(X &x)
{
x.setI(function(i));
}
int function(int val)
{
cout << "To X" << endl;
return val*4; //really a more complex transformation
}
int getJ() { return j; }
void setJ(int j) { this.j=j; }
};
end of file y.hpp------------------
file main.cpp------------------
#include "C:\__trabajo\prog\__cpp\clases\_pruebas\UTM\problema1\X.hpp"
#include "C:\__trabajo\prog\__cpp\clases\_pruebas\UTM\problema1\Y.hpp"
void main(void)
{
X ox;
Y oy;
ox.toY(oy); //ox change to oy
}
end of file main.cpp------------------
but in each file i´m including the class (file) that i want to get, so i get the compiling error:
--------------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
c:\__trabajo\prog\__cpp\clases\_pruebas\utm\problema1\x.hpp(2) : warning C4182: #include nesting level is 363 deep; possible infinite recursion
c:\__trabajo\prog\__cpp\clases\_pruebas\utm\problema1\x.hpp(2) : fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
Error executing cl.exe.
main.obj - 1 error(s), 1 warning(s)
i´ve put the title "OOP Probrem" because i think that is not a c++ error.
How can i make this work? As you see i want to use the take the private data of one of the classes, change it with an algoritmn and put the result in the private data of the other class. And the same in the opposite way.
I want to transform one class to the other one.
Maybe the only way is to use "friends". i ´d be very grateful if you can help me.
Anyway thank you for your patience.
bye