How can I store n-byte data per entry in std::vector, where n is determined at run-time?
For example, suppose class Foo has the following constructor and an add member function:
Foo (int CustomDataSize);
void add (void *PtrCustomData);
At an instance instantiate time, the custom data size is fixed. The later call to add function will store whatever data of size CustomDataSize pointed by the void pointer PtrCustomData into an internal vector in class Foo.
How can I do it? Perhaps declare add as a template function?
Making the class Foo a template class may solve the problem but it is my last option, since I don't want to move all my implementation from the source file (Foo.cpp) to the header file (Foo.h).
Aucun commentaire:
Enregistrer un commentaire