What is the best way to create an array of objects derived from an abstract template base class without violating the strict-aliasing rule. Each derived object will define the template arguments of the base class differently but only through the constant enum value. Here is an example
enum BlaEnum
{
Bla1,
Bla2,
Bla3
};
template <class T, BlaEnum bla = Bla1>
class A
{
public:
virtual void Foo() = 0;
T att;
BlaEnum bll;
};
class B : public A<int, BlaEnum::Bla2>
{
public:
void Foo() override;
};
class C : public A<int, BlaEnum::Bla3>
{
public:
void Foo() override;
};
int main(void)
{
B b;
C c;
//violates strict-aliasing rule
A<int>* BaseArr[2] = { (A<int>*)&b,(A<int>*)&c };
}