C++里面的struct是可以使用template的,然而http://c.biancheng.net/view/2235.html这里竟然说不能用。辣鸡啊。

#include <stdio.h>
#include <iostream>

using namespace std;


template<class T>
struct Box
{
private:
    T x, y;
    T w, h;
public:
    Box<T>(T x_, T y_, T w_, T h_)
    {
        x = x_;
        y = y_;
        w = w_;
        h = h_;
    }
};


int main(){
    Box<float> box_float(1.0, 2.0, 3.0, 4.0);


    return 0;
}

gcc编译毫无压力。

ref: https://stackoverflow.com/questions/2448242/struct-with-template-variables-in-c

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2021-09-22
  • 2022-01-08
  • 2022-12-23
猜你喜欢
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案