2010-11-26 99 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

使用``,而不是``! – rubenvb 2010-11-26 10:22:20

回答

4

您的基地班級期望template template parameter,但你傳遞一個具體的類。使用例如不要使用以下:

using AllocFactor_Core<::AllocFactorScientific>::getFactor; 

注意以下或者因爲類名注射不起作用:在C++

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> >