#ifndef PPP_H
#define PPP_H
#include xxx
namespace yyy
{
class cBlockInfo;
class cSuperMatrix
{
...
};
class cBlockInfo
{
...
};
} // end of namespace
#endif
My question is: what is the use of the first declaration of cBlockInfo, i.e. "class cBlockInfo;" on Line 8? Is it superfluous? Can I simply remove it, since cBlockInfo has its real declaration from Line 15 thru 18?
It's probably necessary. It's called a "forward declaration" and allows cBlockInfo to be used as an incomplete type. It's likely that cSuperMatrix needs it to be forward declared for it to compile.
If SuperMatix doesn't contain a BlockInfo object there's no need for forward declaration there, if it did contain a BlockInfo object or pointer to reference to one (as shown below) then you would need to forward declare it so that it wasn't undefined when SuperMatrix was being compiled.
namespace yyy
{
class cBlockInfo;
class cSuperMatrix
{
public:
cSuperMatrix(void);
~cSuperMatrix(void);
private:
cBlockInfo* bi;
};
class cBlockInfo
{
//definition of cBlockInfo
};
} // end of namespace
Thanks for your comments. Great point! You are right: next doesn't have to be defined right away, it can be assigned at a later time. Then no deadlock at all.