Type of nested structure in template class

template <typename vec1, typename vec2>
class fakevector
{
    public:
       /* Do something */
};



template <class A>
class caller
{
    public:

    struct typeList
    {
        struct typeOne
        {
            //...
        };
    };

    typedef fakevector<typeList::typeOne,int> __methodList;  /* This will trigger compile error */

};

The error messages appeared:

  • Error: type / value mismatch in argument 1 in the template parameter list for the 'fakevector' template class

  • Error: expected type, received 'caller :: typeList :: typeOne

    If the template is removed from the class of the caller, it will be reported without errors like this

    class call {public: struct typeList {....};

I do not know the reason. Thank you very much!

+3
source share
3 answers

Try:

 typedef fakevector<typename typeList::typeOne,int> __methodList;

http://www.comeaucomputing.com/techtalk/templates/#typename

+3
source

It seems that the compiler doubts what typeOne is.

typedef fakevector<typename typeList::typeOne,int> 

should compile

+2

typedef fakevector<typename typeList::typeOne,int>

A prefix typenamefor the name is required if the name

Appears in the template.

Is qualified

It is not used both in the list of specifications of the base class and in the list of element initializers by entering a constructor definition

depends on template parameter

In addition, the prefix is typenamenot allowed if at least the first three previous conditions are not met.

+1
source

Source: https://habr.com/ru/post/1758417/


All Articles