【发布时间】:2021-03-18 22:03:11
【问题描述】:
在 Clang 编译中这给了我错误
template<typename TYPE> struct Base
{
bool variable;
};
template<typename TYPE> struct Ext : Base<TYPE>
{
void clear() {variable=false;} // <- error here
};
错误:使用了未声明的标识符。
来自Why do I have to access template base class members through the this pointer?,我知道一种解决方法是使用“this->variable”,但总是使用起来很痛苦,是否有任何编译器标志可以禁用它?
我正在寻找一个 Clang 编译器标志选项来完全禁用此错误。在 MSVC 上,您可以使用“/permissive”命令行标志来做到这一点。我在 Clang 上寻找类似的选项,但“-fpermissive”标志不起作用。
【问题讨论】:
-
重新发帖无济于事
-
C++ 不允许这样做。你需要一个不同语言的编译器。
-
实际上它确实允许这样做。但是你需要
this->variable=false;来改变variable的查找规则。