Y
Yamin
Hi all,
I was porting some code over to GCC, when I came across some code. GCC gave
a compile error. I looked it over and to me at least it looked like it
should have never compiled. But this code was supposedly compiled on WATCOM
and green hills.
I am assuming GCC is correct in denying the code, but does anyone know how
another compiler would even accept it. Or has anyone come across this
'pattern' before.
Here's a rough outline of the code. Please ignore the syntax. This is just
a rough outline, and its not my code.
BEGIN CODE
***************************************
**************************
pool.h
**************************
template<class T>
class pool
{
....
T *getObject();
void foo(T *x);
};
template<class T>
class T *pool<T>::getObject()
{
....some code
}
template<class T>
void pool<T>::foo(T *x)
{
x->implied(); //implied assumed to be part of class T
}
**************************
control.h
**************************
class A; //forward declare
class B
{
...
pool<A> mypool;
}
class A
{
...
void implied();
B myB;
}
********************************
This to me is a circular reference. To construct B, the size of A needs to
be known (pool<A>). To contruct A, the size of B needs to be known. Even
if A is put in front of B, the same is still true. To be honest, I can't
remeber which came first from the code .
I fixed it already by dynamically assigning the B within A...
Any ideas. Is there something special about templates that allows this to
occur?
Yamin
I was porting some code over to GCC, when I came across some code. GCC gave
a compile error. I looked it over and to me at least it looked like it
should have never compiled. But this code was supposedly compiled on WATCOM
and green hills.
I am assuming GCC is correct in denying the code, but does anyone know how
another compiler would even accept it. Or has anyone come across this
'pattern' before.
Here's a rough outline of the code. Please ignore the syntax. This is just
a rough outline, and its not my code.
BEGIN CODE
***************************************
**************************
pool.h
**************************
template<class T>
class pool
{
....
T *getObject();
void foo(T *x);
};
template<class T>
class T *pool<T>::getObject()
{
....some code
}
template<class T>
void pool<T>::foo(T *x)
{
x->implied(); //implied assumed to be part of class T
}
**************************
control.h
**************************
class A; //forward declare
class B
{
...
pool<A> mypool;
}
class A
{
...
void implied();
B myB;
}
********************************
This to me is a circular reference. To construct B, the size of A needs to
be known (pool<A>). To contruct A, the size of B needs to be known. Even
if A is put in front of B, the same is still true. To be honest, I can't
remeber which came first from the code .
I fixed it already by dynamically assigning the B within A...
Any ideas. Is there something special about templates that allows this to
occur?
Yamin