gpt4 book ai didi

c++ - Visual Studio 2008 编译模板时不关心基类是否存在?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:35:30 25 4
gpt4 key购买 nike

似乎 VS 2008 处理具有继承性的类模板与其他编译器有点不同。以下代码在 VS 2008(使用默认选项)上编译没有任何错误:

template <typename S, typename T>
class someclass : public non_existent_class
{
T operator() (S s) const {
return T(s);
}
};

问题是,为什么?由于未定义的标识符 non_existent_class,没有其他编译器能够做到这一点(尝试过 GCC 4.5.0、Intel、Online Comeau、VS 2005)。也许新的 C++0x 标准中的某些东西证明了这种行为是合理的?

最佳答案

这很可能是因为 visual studio 在本应执行两阶段名称查找时执行了单阶段名称查找。非依赖名称“non_existent_class”应该在第一阶段失败,这发生在定义点,无论模板是否被实例化。

这是一个错误,但在 MS 从根本上改变其编译器使用模板的方式之前,它永远不会被修复。

http://womble.decadent.org.uk/c++/template-faq.html#two-phase

http://blog.llvm.org/2009/12/dreaded-two-phase-name-lookup.html

关于c++ - Visual Studio 2008 编译模板时不关心基类是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5198148/

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