Ian
Ian

Reputation: 21

Template arguments error, C++

I use a fairly complex data structure:

class 1:

template <class T>
class Number
{
private:
            T first;
            T second;

};

class 2:

template <typename Item>
struct TList
{
    typedef std::vector <Item> Type;
};

template <typename Item>
class GList
{
private:
            typename TList <Item>::Type items;

public:
            GList() : items (0) {}


public:
            Item & operator [] (int index ) {return items[index];}
};

class 3:

template <typename T, template <typename> class GList>
class sortIndices 
{

private:
    const GList <T> *l;

public:
    sortIndices ( const GList <T> *l_ ) : l ( l_ ) {}

    bool operator() ( const unsigned int &i_p1, const unsigned int &i_p2 ) const
    {
        return true;
    }

};

class 4:

template <typename T, template <typename> class List>
struct TISet
{
    typedef std::set <unsigned int, sortIndices <T, List> >  Type;
};


template <typename T, template <typename> class List>
struct TSample
{
    T res;
    typename TISet <T, List> ::Type indices;
    TSample ( const List <T> *nl ) : res(0), indices ( nl ) {}
};

class 5:

template <typename T, template <typename> class List>
struct TResults
{
    typedef std::set < TSample <T, List>, sortIndices <T, List> > Type;
};

class 6:

class Test
{
public:
    template <typename T, template <typename> class List>
    static void function (List <T> *l, typename TResults <T, List> ::Type *result) {}
};

The are problems using the following object as argument of the static function...

TResults <double, GList >::Type t_results; 

My first question: How to pass an address of the structure TResults correctly?

Main program:

int main() 
{
    GList <Number <double> *> plist; //Create list of numbers
    TResults <double, GList >::Type t_results; //Create empty results

    Test::function(&plist, &t_results); //ERROR, test function
}

Error code:

Error   1 error C2664: 'void Test::function< Number <T> *, GList>( GList <Item> *,std::set<_Kty, _Pr> *)' :
cannot convert parameter 2 from 'std::set<_Kty,_Pr> *' to 'std::set<_Kty,_Pr> *'

with
      [
          T=double,
          Item=Number<double> *,
          _Kty=TSample<Number<double> *,GList>,
          _Pr=sortIndices<Number<double> *,GList>
      ]
      and
      [
          _Kty=TSample<double,GList>,
          _Pr=sortIndices<double,GList>
      ]
      and
      [
          _Kty=TSample<Number<double> *,GList>,
          _Pr=sortIndices<Number<double> *,GList>
      ]

After modification

class Test
{
public:
    template <typename T, template <typename> class List>
    static void function (typename TResults <T, List> ::Type *result) {}
};

int main() 
{
    GList <Number <double> *> plist; //Create list of numbers
    TResults <double, GList >::Type t_results; //Create empty results

    Test::function(&t_results); //ERROR, test function
}

There is the following error:

Error 1 error C2783: 'void Test::function(TResults::Type *)' : could not deduce template argument for 'T'

Thanks for your time and help...

Upvotes: 1

Views: 698

Answers (2)

Pawel Zubrycki
Pawel Zubrycki

Reputation: 2713

Check http://www.ideone.com/tTETR

I changed types and added comparator parameter to TResults::Type ctor.

Upvotes: 1

aschepler
aschepler

Reputation: 72311

There is no matching specialization. You could call

Test::function( GList<Number<double>*>*, TResults<Number<double>*, GList>::Type* );

or

Test::function( GList<double>*, TResults<double, GList>::Type* );

but the argument types you have don't go together.

Upvotes: 1

Related Questions