【发布时间】:2025-12-15 01:30:02
【问题描述】:
GCC 4.4.1 拒绝在 ctor-initializer 中找到我的 injected-class-name:
template <typename T>
struct Base
{
Base(int x) {}
};
struct Derived : Base<int>
{
Derived() : Base(2) {}
};
int main()
{
Derived d;
}
test2.cpp: In constructor "Derived::Derived()": test2.cpp:9: error: class "Derived" does not have any field named "Base" test2.cpp:9: error: no matching function for call to "Base<int>::Base()" test2.cpp:4: note: candidates are: Base<T>::Base(int) [with T = int] test2.cpp:3: note: Base<int>::Base(const Base<int>&)
不过,GCC 4.8 compiles it just fine。
我确信这应该可行,但我找不到任何不同意我的标准措辞。
这是 GCC 4.4.1 的错误,对吧?
(我确实搜索了 GCC Bugzilla,但没有弹出任何相关内容。)
【问题讨论】:
-
你能在构造函数之外使用
Base吗?也许 GCC 4.4 认为Base是一个从属名称。 -
不确定,但看起来有点像gcc.gnu.org/bugzilla/show_bug.cgi?id=45515
-
@Simple:
Derived不是模板,Base不能依赖于任何模板参数 -
@DavidRodríguez-dribeas 我知道,这就是为什么它是一个错误。 GCC 可能认为是。你可以测试
typename Derived::Base看看是不是这个问题。 -
只是尝试用一些编译它:GCC 4.4.0:失败的 GCC 4.4.1:失败的 GCC 4.4.2:失败的 GCC 4.4.3:失败的 GCC 4.4.4:失败的 GCC 4.4。 5:失败 GCC 4.4.6:失败 GCC 4.4.7:失败 GCC 4.5.0:成功 GCC 4.5.1:成功 GCC 4.5.2:成功 GCC 4.5.3:成功 GCC 4.5.4:成功 GCC 4.6.0:成功 GCC 4.6.1:成功 GCC 4.6.2:成功 GCC 4.6.3:成功 GCC 4.7.0:成功 GCC 4.7.1:成功 GCC 4.7.2:成功 GCC 4.7.3:成功 GCC 4.8.0:成功 GCC 4.8.1:成功 GCC 4.8.2:成功