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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM