Struct with template variables in C++

2019-03-08 02:36发布

I'm playing around with templates. I'm not trying to reinvent the std::vector, I'm trying to get a grasp of templateting in C++.

Can I do the following?

template <typename T>
typedef struct{
  size_t x;
  T *ary;
}array;

What I'm trying to do is a basic templated version of:

typedef struct{
  size_t x;
  int *ary;
}iArray;

It looks like it's working if I use a class instead of struct, so is it not possible with typedef structs?

7条回答
仙女界的扛把子
2楼-- · 2019-03-08 03:39
template <typename T>
struct array {
  size_t x;
  T *ary;
};
查看更多
登录 后发表回答