C ++ template + typedef

What is wrong in the following code:

Point2d.h

template <class T> 
class Point2D 
{     
   private:
         T x;
         T y; 
   ... 
 };

PointsList.h

template <class T>
class Point2D;

template <class T>
struct TPointsList
{
    typedef std::vector <Point2D <T> > Type;
};

template <class T>
class PointsList
{
    private:
            TPointsList <T>::Type points;  //Compiler error
 ...
};

I would like to create a new TPointsList user type without specifying a direct type ...

0
source share
5 answers

Add typename:

...
typename TPointsList<T>::Type points;
...

See Why do we need file_name here?

+5
source

Have you tried using the typename keyword?

template <class T>
class Points2DList
{
    private:
            typename TPoints2DList <T>::Type points;  //using the typename keyword
 ...
};
+4
source

, , , typename , :

typename typedef

+2

, , Point2D Point2D. #include "Point2D.h" PointsList.h. , typename,

TPointsList <T>::Type points;  //Compiler error

typename TPointsList <T>::Type points;
+1

TPoints2DList? .

, TPoints2DList struct, :

   private:
            struct TPointsList <T>::Type points;  //should compile now
-1

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


All Articles