Inheriting from template class

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

Please see comment in code (3 lines above). Basically what happens is that if I have the AllocFactor_Core class as a regular non-template class and when with using directive I just provide name of this class followed by :: and fnc name it works, but as soon as I declare AllocFactor_Core as a template and I try to provide params for it I'm getting beforementioned error.

Upvotes: 1

Views: 332

Answers (3)

Georg Fritzsche
Georg Fritzsche

Reputation: 98984

Your base class expects a template template parameter, but you are passing it a concrete class. Use e.g. the following instead:

using AllocFactor_Core< ::AllocFactorScientific >::getFactor;

Note that the following doesn't work either because of the class name injection:

using AllocFactor_Core< AllocFactorScientific >::getFactor;

Upvotes: 4

tato
tato

Reputation: 5549

When typing nested template parameters, be sure to include at least one space between each >

C++ parser gets confused by

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

It should be

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

Upvotes: -1

Šimon T&#243;th
Šimon T&#243;th

Reputation: 36433

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

Upvotes: 0

Related Questions