This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Support C++ template within template?



Hi TI experts,

I am using CGT v7.3.4, and my code is like below:

 

template<typename TSrc>

funcA(vector<TSrc> *src)

{

vector<int>::iterator iit;

vector<TSrc>::iterator  sed = src ->end() - 1;

...

}

 

I know the first vector is support, but the second vector always gets an error while compile saying expected a ";". I wonder whether the compiler support this kind of embedded template, just like MicroSoft does.

Thanks.

  • Write it like this:

    template<typename TSrc>

    funcA(vector<TSrc> *src)

    {

    vector<int>::iterator iit;

    typename vector<TSrc>::iterator  sed = src ->end() - 1;

    ...

    }

  • It works. Thank you again.

  • what about another case below?

    template <typename RT>

    class Delegate<RT ()>

    {

    ...

    };

    template <typename RT>

    class Event<RT ()>

    {

    private:

    DelegateList m_list;

    typedef Delegate<RT ()> Delegate;

    typedef std::vector<Delegate*> DelegateList;

    ...

    public:

    Event& funcA(const Delegate& delegate)

    {

    DelegateList::iterator it = m_list.begin();

    ...

    }

    };

    ========================================

    compiler error, said: exected a ";"

    I tried to add "typename" before "DelegateList::iterator it = m_list.begin();", but didn't work.

    I also tried to modified the typedef statement "typedef std::vector<Delegate*> DelegateList;" to "typedef typename std::vector<Delegate*> DelegateList;", still didn't work.

    what should I do?

  • When posting about an error message, please be sure to include the complete text, including the line number, so we can figure out what line it refers to.

    You're using the type DelegateList before you've typedefed it.  Move the declaration of m_list below the typedef for DelegateList.

    typedef Delegate<RT ()> Delegate;
    
    typedef std::vector<Delegate*> DelegateList;
    
    DelegateList m_list;

    You'll also need "typename" on the declaration of "it".

    typename DelegateList::iterator it = m_list.begin();