我在 C++ 中有一个旧的工厂实现,我想在其中使用唯一指针而不是原始指针。我的代码的一个最小示例如下。我有一个基类A和一个派生类B。在中main(),我传递1给中的create方法A,而b1现在的类型更改为B.
#include <iostream>
#include <map>
class A {
public:
A() {}
virtual void Foo() {}
std::map<int, A *> ®isterType() {
static std::map<int, A *> map_instance;
return map_instance;
}
A *create(int n) { return registerType()[n]; }
};
class B : A {
public:
B() { registerType()[1] = this; }
void Foo() { std::cout << "I am B!\n"; }
};
static B b0;
int …Run Code Online (Sandbox Code Playgroud) 我发现以下代码没有任何问题,MSVC#编译器将NAN存储在"c"中:
double c = Math.Pow(-8d, 1d / 3d);
Run Code Online (Sandbox Code Playgroud)
虽然我认为这行应该为"c"计算-2,但编译器将NAN存储在"c"中?我错了什么?