gpt4 book ai didi

c++ - GCC 模板问题

转载 作者:行者123 更新时间:2023-11-30 02:11:41 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
problem with template inheritance

此代码无法在 GCC 中编译:

template <typename T>
struct Base
{
public:
int x;
};

template <typename B>
struct Middle : public B
{
};

template <typename T>
struct Sub : public Middle<Base<T> >
{
public:
void F()
{
x=1; // error: ‘x’ was not declared in this scope
}
};

如果 BaseSub 不是模板类,它就不会提示。 VC 处理它。

为什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com