次のような状況があるとします。
class Vertex
{
public:
Position position;
Normal normal;
Texcoord texcoord;
int boneID;
};
class VertexSkinned: public Vertex
{
public:
float boneWeights[3];
int boneIDs[3];
};
class VertexMorphed: public Vertex
{
public:
Position posTargets[3];
Normal normTargets[3];
Texcoord texcoordTargets[3];
};
std::vector<Vertex> vertices;
VertexSkinned vs;
VertexMorphed vm;
Vertex v;
vertices.push_back( vs );
vertices.push_back( vm );
vertices.push_back( v );
// This is illegal right? But how would I go about achieving the desired effect
float someFloat = vertices.front().boneWeights[2];
質問はコメントにあります。私はめったに継承を使用せず、ここで有益な使用法を見つけたかもしれないと考えましたが、それは可能ではないようです。
ポインターのベクトルを使用してから、派生クラスへの動的キャストが機能すると思いますか? これは私がやりたいことではありません。