C++ 导出类(DLL)中静态数据成员的可访问性?
假设我有这个班:C++ 导出类(DLL)中静态数据成员的可访问性?,c++,visual-c++,dll,dllimport,dllexport,C++,Visual C++,Dll,Dllimport,Dllexport,假设我有这个班: class __declspec(dllexport) MyClass { public: static int Bar; static MyOtherClass Foo; private: static int OtherStuff; }; 我有一些问题(我正在使用MSVC编译器): 导入此类的客户端是否可以访问静态成员“Bar” 静态成员“OtherStuff”也会被导出吗?如果不是,这是由于访问修饰符,private: 如果类MyOthe
class __declspec(dllexport) MyClass
{
public:
static int Bar;
static MyOtherClass Foo;
private:
static int OtherStuff;
};
我有一些问题(我正在使用MSVC编译器):
private:
MyOtherClass
未使用\uu declspec(dllexport)
定义,我相信这意味着MSVC编译器将发出警告C4251
,但这是否意味着导入该类的客户端将无法访问变量Foo
class MyOtherClass
{
public:
int something;
};
class __declspec(dllexport) MyClass
{
public:
static int Bar;
static MyOtherClass Foo;
private:
static int OtherStuff;
};
int MyClass::Bar = 0;
MyOtherClass MyClass::Foo;
int MyClass::OtherStuff = 0;
我在Dependency Walker中得到以下信息:
class MyClass & MyClass::operator=(class MyClass const &)
int MyClass::Bar
class MyOtherClass MyClass::Foo
int MyClass::OtherStuff
显然变量
MyClass::Foo
确实已导出,但classMyOtherClass
未导出。如果您试图从该静态变量访问MyOtherClass::something
,我不确定在这种情况下会发生什么。您可能需要构造一个测试DLL,然后在其上运行dumpbin/exports-这将确切地告诉您发生了什么。@Bukes有什么方法可以用Dependency Walker代替检查吗?Dependency Walker当前版本中的exports窗格将显示从DLL导出的所有内容,包括变量和类。您还可以“取消装饰符号”,这将删除一些名称损坏。