|
-
February 21st, 2009, 05:02 PM
#1
Circular includes and forward declarations
Hi, so I'm having a bit of an issue, and I know it has to do with the fact that I have circular includes, but it seems somewhat necessary. Here's essentially what I have:
Code:
// Base.h
#pragma once
#include "SpecificChild.h"
class Base {
SpecificChild* mySpecificChild;
};
Code:
// SpecificChild.h
#pragma once
#include "Base.h"
class SpecificChild : public Base {
};
The issue is that when Base.cpp gets compiled, it includes Base.h. Base.h in turn includes SpecificChild.h. SpecificChild.h tries to include Base.h but sees nothing because of the #pragma once (essentially an #ifdef _BASE_H ... #endif for those not familiar with MSVC). I have had this issue before when I was dealing with two different, unrelated classes, and that was fixed by putting a simple forward declaration in each header file. However, putting "class Base;" above SpecificChild's declaration (and putting "class SpecificChild;" above Base's declaration just in case), still does not help. I get the following error:
"'Base' : base class undefined"
Obviously, and easy and cheap solution to this would be just to change the reference to SpecificChild in Base to just a Base, but I would like to use stuff specific to SpecificChild, and it seems pointless to cast it every time I want to do so.
Is there some specific way of forwardly declaring a class that you intend to use as a base? Thanks.
Last edited by Rossman231; February 21st, 2009 at 05:28 PM.
Reason: Made mySpecificChild a pointer as intended.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|