C++的struct可以使用template

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

posted @ 2019-06-10 18:28  ChrisZZ  阅读(4042)  评论(4编辑  收藏  举报