E
elmar_macek
Hi all,
i have recently stumbled about a problem:
I have implemented a class GeneraBucket, which is superclass for
Bucket and PBucket. I need a method in PBucket that returns a pointer
to a Bucket:
Bucket* PBucket::convertToBucket()
{
return new Bucket(/*some values here*/);
}
Furthermore the Bucket class contains a pointer to a PBucket.
So i tried to solve the problem, that both classes need to know each
other by doing the following:
--- PBucket.hpp ---
//includes and stuff ...
#include "GeneralBucket.hpp"
class Bucket;
class PBucket
ublic GeneralBucket
{
//blabla
Bucket* convertToBucket();
//blabla
}
--- PBucket.cpp ---
#include PBucket.hpp
Bucket* PBucket::convertToBucket()
{
return new Bucket(/*some values here*/);
}
--- Bucket.hpp ---
#include "GeneralBucket.hpp"
#include "PBucket.hpp"
class Bucket
ublic GeneralBucket
{
//blabla
PBucket* upLeftPBuck;
//blabla
}
--- Bucket.cpp ---
//not important
Now i get the following error msges:
..../PBucket.cpp:42: error: invalid use of undefined type 'struct
Bucket'
and
..../PBucket.hpp:10: error: forward declaration of 'struct Bucket'
I really dont understand why, cause i include PBucket.hpp to
Bucket.hpp, which means that the compiler should find the proper
declaration after the forwarding one.
Thanks for your help in advance!
Sincerely
Björn
i have recently stumbled about a problem:
I have implemented a class GeneraBucket, which is superclass for
Bucket and PBucket. I need a method in PBucket that returns a pointer
to a Bucket:
Bucket* PBucket::convertToBucket()
{
return new Bucket(/*some values here*/);
}
Furthermore the Bucket class contains a pointer to a PBucket.
So i tried to solve the problem, that both classes need to know each
other by doing the following:
--- PBucket.hpp ---
//includes and stuff ...
#include "GeneralBucket.hpp"
class Bucket;
class PBucket
{
//blabla
Bucket* convertToBucket();
//blabla
}
--- PBucket.cpp ---
#include PBucket.hpp
Bucket* PBucket::convertToBucket()
{
return new Bucket(/*some values here*/);
}
--- Bucket.hpp ---
#include "GeneralBucket.hpp"
#include "PBucket.hpp"
class Bucket
{
//blabla
PBucket* upLeftPBuck;
//blabla
}
--- Bucket.cpp ---
//not important
Now i get the following error msges:
..../PBucket.cpp:42: error: invalid use of undefined type 'struct
Bucket'
and
..../PBucket.hpp:10: error: forward declaration of 'struct Bucket'
I really dont understand why, cause i include PBucket.hpp to
Bucket.hpp, which means that the compiler should find the proper
declaration after the forwarding one.
Thanks for your help in advance!
Sincerely
Björn