导出类 (DLL) 中静态数据成员的可访问性?
假设我有这个类:
class __declspec(dllexport) MyClass
{
public:
static int Bar;
static MyOtherClass Foo;
private:
static int OtherStuff;
};
我有一些问题(我正在使用 MSVC 编译器):
- 导入此类的客户端是否可以访问静态成员“Bar”?
- 静态成员“OtherStuff”也会被导出吗?如果不是,这是否是由于访问修饰符
private:
造成的? - 如果类
MyOtherClass
未使用__declspec(dllexport)
定义,我相信这意味着 MSVC 编译器将发出警告C4251
,但确实如此这意味着导入此类的客户端将无法访问变量 Foo 吗?
我基本上只是在脑海中运行各种场景,试图仅根据静态数据成员来找出 DLL 类接口中导出的内容和未导出的内容(因此无法访问)。
Suppose I have this class:
class __declspec(dllexport) MyClass
{
public:
static int Bar;
static MyOtherClass Foo;
private:
static int OtherStuff;
};
I have some questions (I'm using an MSVC compiler):
- Will the static member "Bar" be accessible to clients that import this class?
- Will the static member "OtherStuff" also be exported? If not, is this due to the access modifier,
private:
? - If the class
MyOtherClass
is not defined with__declspec(dllexport)
, I believe this means warningC4251
will be issued by the MSVC compiler, but does this mean that variableFoo
will not be accessible to clients that import this class?
I'm basically just running various scenarios through my mind, trying to figure out what is and what isn't exported (and thus inaccessible) in a DLL class interface in terms of static data members only.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于代码:
我在 Dependency Walker 中得到以下内容:
显然变量
MyClass::Foo
确实已导出,但类MyOtherClass
却没有。我不确定如果您尝试从该静态变量访问 MyOtherClass::something 在这种情况下会发生什么。For the code:
I get the following in Dependency Walker:
Apparently variable
MyClass::Foo
is indeed exported, but classMyOtherClass
is not. I'm not sure what happens in this case if you try to accessMyOtherClass::something
from that static variable.