以下代码不能用 gcc 或 clang 编译。
template<class T>
class foo{};
template<class T>
class template_class_with_struct
{
void my_method() {
if(this->b.foo < 1);
};
struct bar
{
long foo;
} b;
};
Run Code Online (Sandbox Code Playgroud)
错误信息是
error: type/value mismatch at argument 1 in template parameter list for 'template<class T> class foo'
8 | if(this->b.foo < 1);
Run Code Online (Sandbox Code Playgroud)
该错误是由模板类 foo 引起的。当编写 <= 而不是 < 1 时,它也会编译。
任何提示赞赏?
CompilerExplorer 链接https://godbolt.org/z/v6Tygo