小编Ani*_*tha的帖子

带有模板参数的共享库

使用以下文件创建共享库

\n\n
example.cpp\n#include <iostream>\ntemplate <typename T>\nT  Max (T & a, T & b) \n{ \n    return a < b ? b:a; \n} \n
Run Code Online (Sandbox Code Playgroud)\n\n

我试图在我的代码中使用上面的库

\n\n
test.cpp\n#include <stdio.h>\n#include <iostream>\nusing namespace std;\n\ntemplate int  Max <int> (int & a, int & b);\ntemplate double  Max <double> (double & a, double & b);\n\nint main ()\n{\n    int i = 39;\n    int j = 20;\n    cout << "Max(i, j): " << Max(i, j) << endl; \n    double f1 = 13.5; \n    double f2 = 20.7; \n …
Run Code Online (Sandbox Code Playgroud)

c++ templates

4
推荐指数
1
解决办法
1331
查看次数

标签 统计

c++ ×1

templates ×1