C++ (Qt)template <class Ti, class Tp>class VVectorIndex: public QObject{ public: VVectorIndex(QObject* parent = 0); virtual ~VVectorIndex(); Ti getIndex(Tp*); Tp* getPointer(Ti); Ti createIndex(Tp* word); bool eraseIndex(Ti); Ti count(){return Indexes.count();}; virtual unsigned char getWordVersion(Ti)=0; virtual bool incrWordVersion(Ti)=0; virtual char getGroupVersion()=0; virtual bool incrGroupVersion()=0; protected: QVector <Tp*> Indexes; private: virtual bool setWordVersion(Tp*word, unsigned char vers){return false;}; char groupVersion; Ti badIndexes;}; class VWord; class VWordIndex: public VVectorIndex<unsigned short, VWord>{public: VWordIndex(QObject* parent = 0):VVectorIndex<unsigned short, VWord>(parent){}; ~VWordIndex(); unsigned char getWordVersion(unsigned short); bool incrWordVersion(unsigned short); char getGroupVersion(); bool incrGroupVersion(); private: bool setWordVersion(VWord *word, unsigned char vers);};
ошибка: undefined reference to `VVectorIndex<unsigned short, VWord>::createIndex(VWord*)'
VWordIndex(QObject* parent = 0):VVectorIndex<unsigned short, VWord>(parent){};
ошибка: undefined reference to `VVectorIndex<unsigned short, VWord>::VVectorIndex(QObject*)'
C++ (Qt)template <class T>class base{public: base() {} virtual ~base() {} virtual void print(const T& x) const = 0; }; class derived : public base<double>{public: virtual void print(const double &x) const { std::cout << "derived.print, x = " << x << std::endl; }}; int main(){ base<double> *base = new derived; base->print(4.5); return 0;}
C++ (Qt) base<double> *base = new derived;
C++ (Qt) base->print(4.5);
C++ (Qt)base<double> *baseD = new derivedD;base<float> *baseF = new derivedF;
C++ (Qt)Расскажите, мне тоже интересно
C++ (Qt)template <class T>struct my_type_traits{typedef T type;typedef T* pointer_type;typedef const T& const_reference;typedef T& reference; // Может содержать свой методы, но обычно это статические функции.. static void some_method(const_reference x) { std::cout << "my_type_traits::some_method, x =" << x << std::endl; }//...}; // Можно сделать специализациию на my_type_traits или написать свойtemplate<>struct my_type_traits<double>{//...static void some_method(const_reference x) { std::cout << " my_type_traits<double>, x = " << x << std::endl; }}; template <class T, class Traits = my_traits<T> >class my_class {public:typedef typename Traits::type type;typedef typename Traits::pointer_type pointer_type;typedef typename Traits::const_reference const_reference;typedef typename Traits::reference reference;//...type my_method(const_reference x) { Traits::some_method(x); //... return x;} // Ну и т.д.}; //Используется это так my_class<int> mi; mi.some_method(2); my_class<double> md;md.some_method(3.14);