相关疑难解决方法(0)

不同类型的三元运算符

下面的代码在g ++ 4.9.2和clang ++ 3.7.0下表现不同.哪一个是正确的?标准中的哪一部分与此相关?谢谢.

#include <iostream>
using namespace std;

struct Base {
  Base() = default;
  Base(const Base&) = default;
  Base(Base&&) = delete;
};

struct Derived : Base {
};

int main() {
  const Base& b = true ? Derived() : Base();
}
Run Code Online (Sandbox Code Playgroud)

g ++接受它并且clang ++给出错误incompatible operand types ('Derived' and 'Base').请参阅下文了解详情.

[hidden]$ g++ -v
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id …
Run Code Online (Sandbox Code Playgroud)

c++ c++11 c++14

17
推荐指数
1
解决办法
2841
查看次数

标签 统计

c++ ×1

c++11 ×1

c++14 ×1