Hi,
I was wondering if it was possible to get a "compiler constant" inside a class?
What I meant with [Compiler constant] is the kind of constant that works with case statement or #defined or likes Enums and not just a Read-Only.
I have a base class that looks like
template<typename>
class IBaseComponent :public BaseComponent
{
public:
const unsigned int getType()
{
return typeID;
}
static const unsigned int typeID;
};
I have a Derived class
class TransformComponent: public IBaseComponent<TransformComponent>
{
public:
TransformComponent();
//Relative to the Window
Vector2<int> position;
//Pixel count and not Multiply
Vector2<int> size;
//Yet TBD
Vector2<int> rotation;
};
.cpp
const unsigned int IBaseComponent<TransformComponent>::typeID = 1000;//<-- The nr doesnt matter
The reason why I "need" a compiler const is that I need it for a switch statement
for(std::map<int,BaseComponent*>::const_iterator it = t->GetComponents()->begin(); it != t->GetComponents()->end(); it++)
{
switch(it->second->getType())
{
{
break;
}
}
}
Like so, but case statement seems to require constant that is known when compiling/Linking. A alternative method to switch is that I can just use
for(std::map<int,BaseComponent*>::const_iterator it = t->GetComponents()->begin(); it != t->GetComponents()->end(); it++)
{
if(it->second->getType() == IBaseComponent<TransformComponent>::typeID)
{
//Do stuffs
}
}
But for my curiosity, is the a way to make it work?
enum test
{
a
};
const unsigned int IBaseComponent<TransformComponent>::typeID = test::a; <--- tried to do this but to no avail