I’m using Visual Studio 2008 Express edition, and keep getting the following error:
"Cascadedisplay.h(4) : fatal error C1014: too many include files : depth = 1024.
Obviously I’m doing something very wrong with include files, but I just can’t see what.
Basically, I have an interface class, StackDisplay, from which I want to derive CascadeDisplay in another file:
#if !defined __BASE_STACK_DISPLAY_H__
#define __BASE_STACK_DISPAY_H__
#include <boost\shared_ptr.hpp>
#include "CascadeDisplay.h"
namespace Sol
{
class StackDisplay
{
public:
virtual ~StackDisplay();
static boost::shared_ptr<StackDisplay>
make_cascade_display(boost::shared_ptr<int> csptr)
{
return boost::shared_ptr<StackDisplay>(new CascadeDisplay(csptr));
}
};
}
#endif
and then in CascadeDisplay.h:
#if !defined __CASCADE_DISPLAY_H__
#define __CASCADE_DISPAY_H__
#include "StackDisplay.h"
#include <boost\shared_ptr.hpp>
namespace Sol
{
class CascadeDisplay: public StackDisplay
{
public:
CascadeDisplay(boost::shared_ptr<int> csptr){};
};
}
#endif
So what’s up with that?
Is
#if !defined...legit? I always used#ifndef.Either way, why does your “base” class require the reference to
CascadeDisplay? That doesn’t seem right. Consider replacing your call to create a newCascadeDisplaywith a call to a pure virtual function inStackDisplaythat your subclass must implement appropriately.IE, something like (and forgive, I don’t have a c++ compiler handy to check this):
I believe this solution is superior, in general, to the forward declaration because you’re eliminating some tight coupling between your superclass and your subclass, and making a more generic interface besides. This lets you eliminate the
#includeof CascadeDisplay.h in StackDisplay.h.