Наследование от шаблонного класса - PullRequest
1 голос
/ 26 ноября 2010
            #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 как обычный не шаблонный класс, и когда с помощью директивы using я просто предоставляю имя этого класса, за которым следуют :: и fnc name, он работает, но как только я объявляю AllocFactor_Core как шаблони я пытаюсь предоставить параметры для этого, я получаю вышеупомянутую ошибку.

Ответы [ 3 ]

4 голосов
/ 26 ноября 2010

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

using AllocFactor_Core< ::AllocFactorScientific >::getFactor;

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

using AllocFactor_Core< AllocFactorScientific >::getFactor;
0 голосов
/ 26 ноября 2010

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

C ++ синтаксический анализатор запутывается

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

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

AllocFactor_Core<AllocFactorScientific<Mantissa,Exponent,Base,Tag> >
0 голосов
/ 26 ноября 2010

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...