2010-11-26 3 views
1
  #include <iostream> 
      #include <math.h> 
      using namespace std; 

      template<template<short,short,short,int> class Derived> 
       struct AllocFactor_Core 
       { 

       private: 
        static long double factor_; 
        static long double calcFactor_(const short mantissa, const short exponent,const short base) 
        { 

         return mantissa * ::pow(static_cast<long double>(base),exponent); 
        } 
       public: 
        static const long double getFactor() 
        { 
         return factor_; 
        } 

        void setFactor(const short mantissa,const short exponent,const short base) 
        { 
         factor_ = calcFactor_(mantissa,exponent,base); 
        } 
        void setFactor(const long double factor) 
        { 
         factor_ = factor; 
        } 

       }; 

       template<short Mantissa, short Exponent, short Base = 10, int Tag = 0> 
       struct AllocFactorScientific : private AllocFactor_Core<AllocFactorScientific> 
       { 
        static short base_; 
        using AllocFactor_Core<AllocFactorScientific<Mantissa,Exponent,Base,Tag>>::getFactor; 
     //I'm getting an error here saying: error: type/value mismatch at argument 1 in template 
     //parameter list for 'template<template<short int <anonymous>, short int <anonymous>, short int 
    // <anonymous>, int <anonymous> > class Derived> struct AllocFactor_Core'| 
        }; 
       template<short Mantissa, short Exponent, short Base, int Tag> 
       short AllocFactorScientific<Mantissa, Exponent, Base,Tag>::base_ = Base; 

См. Комментарий в коде (3 строки выше). В основном, что происходит, если у меня есть класс AllocFactor_Core как обычный класс без шаблона, и когда с помощью директивы я просто предоставляю имя этого класса, за которым следуют :: и имя fnc, это работает, но как только я объявляю AllocFactor_Core в качестве шаблона и я пытаюсь предоставить параметры для него. Я получаю ошибку, описанную выше.Наследование с шаблона класса

+1

Использование `` вместо `` в C++! – rubenvb 2010-11-26 10:22:20

ответ

4

Ваша база класс ожидает template template parameter, но вы передаете ему конкретный класс. Использовать, например. следующие вместо:

using AllocFactor_Core<::AllocFactorScientific>::getFactor; 

Обратите внимание, что следующий не работает, либо из-за введения имени класса:

using AllocFactor_Core<AllocFactorScientific>::getFactor; 
0

AllocFactor_Core<AllocFactorScientific<Mantissa,Exponent,Base,Tag>> должен быть AllocFactor_Core<AllocFactorScientific>

+0

@Let_Me_Be nope ... Я поменялся так, как вы предлагали, и все еще эта ошибка – 2010-11-26 10:19:52

+0

@There Ну, это определенно должно сообщать о другой ошибке. Какова должна использоваться директива по использованию? – 2010-11-26 10:20:51

-1

При вводе вложенных параметров шаблона, обязательно включают в себя по крайней мере один пробел между>

анализатором

C++ путается по

AllocFactor_Core<AllocFactorScientific<Mantissa,Exponent,Base,Tag>> 

Это должно быть

AllocFactor_Core<AllocFactorScientific<Mantissa,Exponent,Base,Tag> > 
Смежные вопросы