假设我有这样的情况:
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];
问题在评论中。我很少使用继承,并认为我可能在这里找到了有益的用途,尽管这似乎不可能。
我假设使用指针向量然后动态转换为派生类有效吗?不过,这不是我想做的。