C++ (Qt)class CUser { ... CList * mList;};
C++ (Qt)struct CList {...}; template <class T>struct CListVec : public CList, public std::vector <T> {...}; // теперь я могу написать напрmList = new CListVec <float>;
C++ (Qt)mList->size()(*mList)[ 1 ]
mList = new CListVec <float>;int CList_size = static_cast<CList*>(mList)->size();size_t vector_size = static_cast<std::vector<float>*>(mList)->size();
C++ (Qt)template <class T>struct CListVec : public CList, public std::vector <T> {...};
C++ (Qt)template <class T>class CUser { ... std::vector <T> * mList;};
class User{ ...private: void* mList; // pointer to vector<int>, vector<float> ...};template <typename T>class TheUser : public User{ ...public: const std::vector<T>* mList() const { return static_cast<const std::vector<T>*>(mList); }};TheUser<float> floatUser;
C++ (Qt)void append( (( mType )? float : double) item )
C++ (Qt)#include <vector> struct CList { virtual size_t size ( void ) = 0; virtual double GetDoub ( size_t index ) = 0;}; template <class T>struct CListVec : public CList { CListVec( const T & elem ) { mVec.push_back(elem); } virtual size_t size ( void ) { return mVec.size(); } virtual double GetDoub ( size_t index ) { return mVec[index]; } std::vector <T> mVec;}; int main(int argc, char *argv[]){ (void) argc; (void) argv; CList * vecLst1 = new CListVec <double> (0.123); CList * vecLst2 = new CListVec <float> (0.456f); double d1 = vecLst1->GetDoub(0); double d2 = vecLst2->GetDoub(0); printf("d1 = %g, d2 = %g, size = %ld\n", d1, d2, vecLst1->size()); return 0;}