我想知道为什么对静态函数的调用是模糊的,即使其中一个显然不可能调用,因为它是私有的.我希望我可以使用私有/受保护的继承来帮助编译器解决歧义.
它是特定于MSVC还是以某种方式在标准中指定?
struct A
{
static int num() { return 0; }
};
struct B
{
static int num() { return 1; }
};
struct C : public A, private B
{};
int main()
{
C::num(); // Ambiguous access of num
}
Run Code Online (Sandbox Code Playgroud)
背景是我试图通过继承它来重用许多派生类(C,D,E,F,G)中的重载行为(A中的那个),以某种方式遵守不重复的规则你自己.
我在Windows上,使用MSVC来编译我的项目,但是我需要克服其整洁的AST解析器,这允许我编写一个小代码生成器.
问题是,clang无法解析MSVC头文件(一个众所周知且易于理解的问题).
我尝试了两种选择:
<string>包含类似的内容时都会导致完全失败并且解析得不多.我正在使用python绑定(libclang),但如果有解决方案,我会考虑切换到C/C++ API.
无论如何我可以改变这种行为并使clang继续解析,即使找不到某些标题?
下面的代码在Visual Studio 2013下会崩溃
我想知道为什么:在这种情况下编写移动构造函数的正确方法是什么?删除移动构造函数可以解决问题。这是 VC++ 的错误还是这段代码有错误?
移动构造函数的默认定义有什么不同,可以使此代码不会崩溃,而我自己的定义却会崩溃?
#include <memory>
#include <vector>
class A
{};
class Foo
{
public:
Foo(std::unique_ptr<A> ref) : mRef(std::move(ref)) {}
Foo(Foo&& other) : mRef(std::move(other.mRef)) {}
Foo(const Foo& other) {}
Foo& operator=(const Foo& other) { return *this; }
protected:
std::unique_ptr<A> mRef;
};
int main(int argc, char *argv[])
{
std::vector<Foo>({ Foo(std::make_unique<A>()), Foo(std::make_unique<A>()) });
// Crash : Debug Assertion Failed !
// Expression : _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
}
Run Code Online (Sandbox Code Playgroud)
可能与此有某种关系,对吧?
与 2013 年相比,initializer_list 中的双重删除
这是带有充实的复制构造函数和赋值的实际代码,但错误是完全相同的
class A
{
public:
std::unique_ptr<A> clone() { return …Run Code Online (Sandbox Code Playgroud)