想象一下我有这样的图书馆:
图书馆.h
class DLLEXPORT LibraryClass
{
private:
int _id;
static int _last_id;
public:
LibraryClass();
bool operator == (const LibraryClass t)
{return _id == t._id;}
};
图书馆.cpp
#include "Library.h"
int LibraryClass::_last_id = 0;
LibraryClass::LibraryClass()
_id(_last_id)
{
++_last_id;
}
它会正确工作吗?我在 Visual Studio 中收到 C4835 警告,但它似乎有效。有谁知道它将如何在其他编译器上工作(我对 linux gcc 和 mac gcc 感兴趣)?这种模式是否有另一种“有效”实现?