I am building an application where there are multiple classes that inherit from a single base class. Let’s say I have this declaration:
ref class WorkScreenBase abstract
{
internal:
WorkScreenBase(void);
bool isLoaded;
}
I have several classes that implement it, for example:
ref class MainScreen : public WorkScreenBase
{
internal:
MainScreen(void);
~MainScreen(void);
}
In another part of the application, I want to have a container for any potential implementation of WorkScreenBase, so I am trying to use:
WorkScreenBase^ myCurrentBase;
However, it appears that this would be illegal. What would be the best way to approach the problem?
UPDATE: I could use a MainScreen^ myCurrentScreen, but would much rather use the base class as the reference point for flexibility reasons.
The issue was fixed in a way that I did not expect (at least according to the compiler error thrown). The problem was in the header file cross-reference. Somehow, both with header guards and
#pragma once, I ended up with a circular .h reference.So, conclusion:
problem.
#pragma onceare good, but won’t help you against that.