Is there a way to make a pure virtual enumeration?
If not, any suggestions how I could get a similar effect?
Here is the code I'm working with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <stdio.h>
class System
{
private: enum ERROR_FLAG; //can make pure virtual?
virtual void PostError(ERROR_FLAG _error) = 0;
public: virtual void Update() = 0;
};
class Graphics : private System
{
private: enum ERROR_FLAG { ERR_LOST_DEVICE };
void PostError(ERROR_FLAG _error);
public: Graphics();
void Update();
};
Graphics::Graphics()
{
}
void Graphics::Update()
{
PostError(ERR_LOST_DEVICE);
}
void Graphics::PostError(ERROR_FLAG _error)
{
printf("Error message sent.\n");
}
int main()
{
Graphics graphics; //ERROR: cant instantiate abstract class
return 0;
}
|
Right now I get an error saying:
error C2259: Graphics cannot instantiate abstract class due to following members:
'void System::PostError(System::ERROR_FLAG)' is abstract
...
I understand the problem is that the functions' signatures don't match.
void PostError(System::ERROR_FLAG)
void PostError(Graphics::ERROR_FLAG)
Making a few changes fixes this but I get a new error. This is not what I want
anyways. I want to force other classes that inherit from System to be required
to define an ERROR_FLAG enumeration.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <stdio.h>
class System
{
private: virtual enum ERROR_FLAG; //change
virtual void PostError(ERROR_FLAG _error) = 0;
public: virtual void Update() = 0;
};
class Graphics : private System
{
private: enum ERROR_FLAG { ERR_LOST_DEVICE };
void PostError(::ERROR_FLAG _error); //change
public: Graphics();
void Update();
};
Graphics::Graphics()
{
}
void Graphics::Update()
{
PostError(ERR_LOST_DEVICE); //ERROR: ERR_LOST_DEVICE incompatible
}
void Graphics::PostError(::ERROR_FLAG _error) //change
{
printf("Error message sent.\n");
}
int main()
{
Graphics graphics; //fixed
return 0;
}
|
Thanks