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
原文链接: https://www.cnblogs.com/zjutzz/p/10999439.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/296480
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!