以下代码片段在 Clang 3.4/3.5 (Xcode 5/6) 下构建完美,但在 Visual C++ 14 CTP3 下抛出错误:
1>------ Build started: Project: InheritingConstructor, Configuration:
Debug Win32 ------ 1> inheritingconstructor.cpp(60): error C2661:
'D::D': no overloaded function takes 2 arguments
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
代码确实通过尝试从基类继承模板构造函数给编译器施加了一些压力,也许这就是 Visual C++ 在竞争中再次失败的地方?或者我遇到了一些灰色区域,从而导致标准中的未定义行为?
#include "stdafx.h" // comment out this line for Xcode build
#include <iostream>
#include <type_traits>
template <typename X>
struct B
{
int i;
B(int i_) : i(i_) {}
template < typename T, typename = typename std::enable_if<
std::is_same<T, X>::value >::type >
B(const T*, const T*) : i(0) {}
};
struct D : B<D>
{
using B<D>::B; // inherit constructors from B
};
int main(int argc, const char * argv[]) {
// insert code here...
D d((D*)nullptr, (D*)nullptr);
std::cout << "Hello, World!\n";
return 0;
}
最佳答案
从标准合规性的角度来看,您的代码没有任何问题。
继承构造函数未在 VC++2013 中实现 LINK .
然而,像这样LINK建议自 VC++2014 CTP 1 以来实现这种功能。
深入挖掘,我发现今天早上报告了具有相同示例的完全相同的错误 LINK .
底线:这是一个已报告的 VC++2014 错误。
关于c++ - 视觉 C++ 14 CTP3 : c++11 inheriting constructor bug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26148314/