visual-c++ - Visual Studio 中嵌套模板的一致性模式和多重继承

标签 visual-c++ namespaces multiple-inheritance

在尝试检查一个类是否从另一个类派生时,我遇到了(在我看来是)Visual Studio 的奇怪行为。考虑以下示例:

样本 1

namespace X
{
    namespace Y
    {
        struct A {};
        struct B {};
    }
}

struct AB : public X::Y::A, public X::Y::B {};

static_assert(std::is_base_of_v<X::Y::A, AB>); // (1)
static_assert(std::is_base_of_v<X::Y::B, AB>); // (2)

样本 2
namespace X
{
    namespace Y
    {
        struct A {};
        struct B {};
    }
}

using namespace X::Y;
struct AB : public A, public B {};

static_assert(std::is_base_of_v<A, AB>); // (3)
static_assert(std::is_base_of_v<B, AB>); // (4)

我添加了 /std:c++latest Visual Studio 中的选项,所以据我所知,嵌套命名空间应该没问题。

如果我设置 Conformance Mode在 Visual Studio 中为 No,则所有 static_assert满足上述表达式。

但是,如果我将其设置为 Yes(即 /permissive- ),则满足 (3) 但所有 (1)、(2) 和 (4) 均失败。我很感激任何人都可以提供为什么会出现这种情况的见解 - 是我的理解有问题,还是 VS 问题?特别是,(3) 和 (4) 可以(并且确实!)不同的事实非常奇怪。

最佳答案

IntelliSense 错误地将它们标记为失败,但如果您尝试构建项目,它将成功编译。

Intellisense 不是功能齐全的编译器,它可能不那么准确或可能不会更新以支持最新的语言功能,并且有时与编译器不一致。

关于visual-c++ - Visual Studio 中嵌套模板的一致性模式和多重继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50865602/

相关文章:

c++ - 在类名之前使用宏在 C++ 中类

c++ - 向许多文件添加 namespace 声明?

c++ - 在 C++ 中组合接口(interface)

c++ - 我可以让函数调用软编码吗?

c++ - 如何找到编译瓶颈?

actionscript-3 - 是否可以从其他包访问包外的类?

java - 如何在Java中使用单应方法实现接口(interface)?

python - 什么是 mixin,它为什么有用?

c++ - 为什么 VS2012 无法识别 C++ 项目中的某些 C++11 关键字?

php - 代码点火器 : Sendmail cannot use Mailgun\Mailgun - it is not a trait Composer