有谁知道这个文字是什么意思? (与C4251警告有关) [英] Does anyone know what this text means? (related to C4251 warning)

查看:81
本文介绍了有谁知道这个文字是什么意思? (与C4251警告有关)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MS网站上: http: //msdn2.microsoft.com/en-us/lib...1w(VS.80).aspx


如下乱码:


"你可以通过定义一个用虚拟函数定义类

的DLL来避免导出类,你可以调用实例化的函数和

删除该类型的对象。然后你可以在

类型上调用虚函数。

有没有人真正理解所说的内容?一个简单的例子

会有所帮助。

解决方案

BTW David的方式就是这篇文章所指的内容。继承通过聚合和实现相同的公共接口完成

。实际的

具体类在公共头文件中不存在,只有纯

接口(仅包含纯虚函数)。工厂函数

必须是全局的,以避免名称错位问题,它们将在公共头文件中以原型进行。销毁应该是

v表中的Dispose函数,它调用delete this;,避免强制转换,或者如果使用引用

count则使用AddRef / v-table中的释放功能。


道格的方式虽然可以避免警告,但是

警告的所有内容都是为了劝阻(导出类成员,违反

单一定义规则等)。





Ben Voigt [C ++ MVP]写道:


BTW大卫的方式就是这篇文章所指的内容。继承通过聚合和实现相同的公共接口完成

。实际的

具体类在公共头文件中不存在,只有纯

接口(仅包含纯虚函数)。工厂函数

必须是全局的,以避免名称错位问题,它们将在公共头文件中以原型进行。销毁应该是

v表中的Dispose函数,它调用delete this;,避免强制转换,或者如果使用引用

count则使用AddRef / v-table中的释放功能。


道格的方式虽然可以避免警告,但是

警告的所有内容都是为了劝阻(导出类成员,违反

单一定义规则等)。



只是为了确保我们'' 在同一页面上:


从上面的内容来看,David的示例标题应该包含这样的行

有点像这样:


//标题

IBase * DECLSPEC_MACRO CreateClass();

void DECLSPEC_MACRO DestroyClass(IBase * pBase);


其中DECLSPEC_MACRO只是评估为

__declspec(dllimport / dllexport)视情况而定


我的理解是否正确?


另外,你能解释一下吗?在你的回复中是段落:


销毁应该是v表中的Dispose函数,它调用

" delete this;"


当然,如果构造/销毁是全局函数,那么它们是否b / b $ b'不能有''这个'指针?


你做错了,或者我错过了什么?




" Anonymous" < no ****** @ here.comwrote in message

news:MY ************************ ****** @ bt.com ...


>


Ben Voigt [C ++ MVP]写道:


> BTW大卫的方式就是文章所指的方式。通过聚合和实现相同的公共接口来完成继承。公共头文件中不存在实际的具体类,只有纯粹的
接口(仅包含纯虚函数)。工厂的功能必须是全局的以避免名称损坏问题,它们将在公共头文件中进行原型化。销毁应该是v-table中的Dispose
函数,它调用delete this;,避免强制转换,或者
如果使用引用计数,那么
中的AddRef / Release函数v-table。

道格的方式,虽然它可以避免警告,但所有的事情都是为了阻止(出口班级成员,违反了一个警告) - 定义规则等)。




只是为了确保我们在同一页面上:


来自你如上所述,David的示例标题应该包含这样的行




//标题

IBase * DECLSPEC_MACRO CreateClass();

void DECLSPEC_MACRO DestroyClass(IBase * pBase);



差不多,除非你使用自毁。


另外,使用out参数很常见而不是

新对象的返回值,例如:

HRESULT DECLSPEC_MACRO CreateClass(IBase ** pRetval);


>

其中DECLSPEC_MACRO只是评估为__declspec(dllimport / dllexport)

视情况可能是


和MY_LIBRARY_DLL是一个比DECLSPEC_MACRO更好的名字


>

我的理解是否正确?


另外,你能否在回复中解释这一段:


销毁应该是v-table中的Dispose函数,它调用

"删除这个;"


当然,如果构造/销毁是全局函数,那么它们可以'/ b $ b'''''有一个''this''指针?


Dis y你犯了一个错误,或者我错过了什么?



这将是一个虚拟成员函数Dispose而不是全局

销毁函数,因为全局销毁函数必须执行

cast,而成员函数非常确定对象是正确类型的



On MS site: http://msdn2.microsoft.com/en-us/lib...1w(VS.80).aspx

is the following garbled rambling:

"You can avoid exporting classes by defining a DLL that defines a class
with virtual functions, and functions you can call to instantiate and
delete objects of the type. You can then just call virtual functions on
the type."
Does anyone actually understand what is being said?. A simple example
would help.

解决方案

BTW David''s way is what the article is referring to. Inheritance is done
via aggregation and implementing the same public interface. The actual
concrete class is not present in the public header file, only the pure
interface (contains only pure virtual functions) is. The factory functions
must be global to avoid name mangling issues, they would be prototyped in
the public header file. Destruction should be a Dispose function in the
v-table which calls "delete this;", avoiding the cast, or if reference
counting is used then AddRef/Release functions in the v-table.

Doug''s way, although it might avoid the warning, does all the things the
warning is designed to discourage (exports class members, violates
one-definition rule, etc).




Ben Voigt [C++ MVP] wrote:

BTW David''s way is what the article is referring to. Inheritance is done
via aggregation and implementing the same public interface. The actual
concrete class is not present in the public header file, only the pure
interface (contains only pure virtual functions) is. The factory functions
must be global to avoid name mangling issues, they would be prototyped in
the public header file. Destruction should be a Dispose function in the
v-table which calls "delete this;", avoiding the cast, or if reference
counting is used then AddRef/Release functions in the v-table.

Doug''s way, although it might avoid the warning, does all the things the
warning is designed to discourage (exports class members, violates
one-definition rule, etc).


Just to make sure we are ''on the same page'':

From what you say above, David''s example header should include lines
somewhat like this:

// Header
IBase* DECLSPEC_MACRO CreateClass() ;
void DECLSPEC_MACRO DestroyClass(IBase* pBase) ;

Where DECLSPEC_MACRO simply evaluates to a
__declspec(dllimport/dllexport) as the case may be

Is my understanding correct ?

Also, could you please explain this paragraph in your response:

"Destruction should be a Dispose function in the v-table which calls
"delete this;"

Surely, if the Construction/Destruction are global functions, then they
can''t have a ''this'' pointer?

Dis you make a mistake, or am I missing something ?



"Anonymous" <no******@here.comwrote in message
news:MY******************************@bt.com...

>

Ben Voigt [C++ MVP] wrote:

>BTW David''s way is what the article is referring to. Inheritance is done
via aggregation and implementing the same public interface. The actual
concrete class is not present in the public header file, only the pure
interface (contains only pure virtual functions) is. The factory
functions must be global to avoid name mangling issues, they would be
prototyped in the public header file. Destruction should be a Dispose
function in the v-table which calls "delete this;", avoiding the cast, or
if reference counting is used then AddRef/Release functions in the
v-table.

Doug''s way, although it might avoid the warning, does all the things the
warning is designed to discourage (exports class members, violates
one-definition rule, etc).



Just to make sure we are ''on the same page'':

From what you say above, David''s example header should include lines
somewhat like this:

// Header
IBase* DECLSPEC_MACRO CreateClass() ;
void DECLSPEC_MACRO DestroyClass(IBase* pBase) ;

Pretty much, unless you use self-destruction.

Also, it''s common to use an out parameter instead of a return value for the
new object, like:

HRESULT DECLSPEC_MACRO CreateClass(IBase** pRetval);

>
Where DECLSPEC_MACRO simply evaluates to a __declspec(dllimport/dllexport)
as the case may be

and MY_LIBRARY_DLL is a better name than DECLSPEC_MACRO

>
Is my understanding correct ?

Also, could you please explain this paragraph in your response:

"Destruction should be a Dispose function in the v-table which calls
"delete this;"

Surely, if the Construction/Destruction are global functions, then they
can''t have a ''this'' pointer?

Dis you make a mistake, or am I missing something ?

This would be a virtual member function Dispose instead of a global
destruction function, because the global destruction function has to do a
cast, whereas a member function is pretty well assured that the object is
the correct type.


这篇关于有谁知道这个文字是什么意思? (与C4251警告有关)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆