救救孩子吧
实在不知道怎么回事,就是不能实现不输类型运行,模板类型不是可以自动识别吗?程序代码:
#include <iostream> using namespace std; template<class T> class sring{ public: T data; constexpr sring(T d):data(d){} }; int main(){ sring a=1; cout<<a.data; }
结果是这样,gcc,windows上
程序代码:
c:\c++>g++ shiyan.cpp shiyan.cpp: In function 'int main()': shiyan.cpp:18:11: error: missing template arguments before 'a' sring a=1; ^ shiyan.cpp:19:11: error: 'a' was not declared in this scope cout<<a.data;