我想在命令start和end函数模板中使用一个带有成员变量的简单结构:
#include <iostream>
using namespace std;
struct st {
int start;
int end;
};
template<typename T>
void compare(const T& v1, const T& v2){
if(v1.end < v2.end)
cout << "v1 < v2" << endl;
}
int main() {
st a = {1, 2};
st b = {2, 3};
compare(a, b);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是这个程序无法在mingw g ++ 4.8.2上编译:
main.cpp: In function 'void compare(const T&, const T&)':
main.cpp:11:11: error: parse error in template argument list
if(v1.end < v2.end)
^ …Run Code Online (Sandbox Code Playgroud)