Instead of
typedef struct
{
double x,y;
} Point;
C++11 supports
using Point = struct {double x, y;};
Unfortunately, this approach does not work for the type T
template <typename T>
using Point = struct {T x, y;};
Is there any way of resolving the problem?
using Point = ...;
is a type alias (formally called just 'alias'). I.e., it's just a different syntax for typedef
where the type involved is named in ...
.
template<typename T> using Point = ...;
is an alias template, where the type involved is again named in ...
.
What both aliases and alias templates have in common is that both must refer to a type-id (C++11 [basic.scope.pdecl]p3). Type-ids must in turn name types. (Go figure.)
The problem is that template<typename T> struct {T x, y;}
is not a type, but a class template, and as just established alias templates must refer to types. As to changing your code to resolve your problem, I've no idea as you haven't said what it is... ;-] Regarding that, please see What is the XY problem?