功能复制可能吗? [英] Is function copy possible?

查看:76
本文介绍了功能复制可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。假设存在C ++的实现,其中当分配

类对象时,其成员函数也在其数据成员的

中分配。这样每个类对象都有一个副本

的所有成员函数。当一个成员函数被调用时,它是对象'的副本,当一个类对象被释放时,

对应的成员函数也被释放。


不要考虑优化或性能,

1.这样的实现是否可行?

2.是否有这样的实现是否符合ISO C ++标准?

Hello. Suppose there is an implementation of C++, in which when a
class object is allocated, its member functions are also allocated in
addition to its data members. So that every class object has a copy
of all of its member functions. When a member function is called, it''s
the object''s copy that When a class object is deallocated, the
corresponding member functions are also deallocated.

Don''t consider optimization or performance,
1. Is such an implementation possible?
2. Does such an implementation conform to the ISO C++ standard?

推荐答案

WaterWalk写道:
WaterWalk wrote:
$ b $你好假设存在C ++的实现,其中当分配

类对象时,其成员函数也在其数据成员的

中分配。这样每个类对象都有一个副本

的所有成员函数。当一个成员函数被调用时,它是对象'的副本,当一个类对象被释放时,

对应的成员函数也被释放。


不要考虑优化或性能,

1.这样的实现是否可行?
Hello. Suppose there is an implementation of C++, in which when a
class object is allocated, its member functions are also allocated in
addition to its data members. So that every class object has a copy
of all of its member functions. When a member function is called, it''s
the object''s copy that When a class object is deallocated, the
corresponding member functions are also deallocated.

Don''t consider optimization or performance,
1. Is such an implementation possible?



您可以描述JavaScript,其中函数可以用作对象。

You could be describing JavaScript, where functions can be used as objects.


2.是否这样一个实现是否符合ISO C ++标准?
2. Does such an implementation conform to the ISO C++ standard?



不,对于一个,你怎么能得到这些对象之一的地址

会员功能?


-

Ian Collins。

No, for one, how could you take the address of one of these object''s
member functions?

--
Ian Collins.


11月13日,6日:04 pm,Ian Collins< ian-n ... @ hotmail.comwrote:
On Nov 13, 6:04 pm, Ian Collins <ian-n...@hotmail.comwrote:

WaterWalk写道:
WaterWalk wrote:

您好。假设存在C ++的实现,其中当分配

类对象时,其成员函数也在其数据成员的

中分配。这样每个类对象都有一个副本

的所有成员函数。当一个成员函数被调用时,它是对象'的副本,当一个类对象被释放时,

对应的成员函数也被释放。
Hello. Suppose there is an implementation of C++, in which when a
class object is allocated, its member functions are also allocated in
addition to its data members. So that every class object has a copy
of all of its member functions. When a member function is called, it''s
the object''s copy that When a class object is deallocated, the
corresponding member functions are also deallocated.


不要考虑优化或性能,

1.这样的实现是否可行?
Don''t consider optimization or performance,
1. Is such an implementation possible?



您可以描述JavaScript,其中函数可以用作对象。


You could be describing JavaScript, where functions can be used as objects.


2.是否这样一个符合ISO C ++标准的实现?
2. Does such an implementation conform to the ISO C++ standard?



不,对于其中一个,你如何获取其中一个对象'

成员函数的地址?


No, for one, how could you take the address of one of these object''s
member functions?



仍然可以通过在对象内添加类

对象的地址和成员函数偏移来计算成员函数地址。

调用函数时,只需将函数起始地址放入

指令寄存器。

Member function address can still be calculated by adding the class
object''s address and the member function offset inside the object.
When calling a function ,just put the function starting address into
the instruction register.


WaterWalk写道:
WaterWalk wrote:

你好。假设存在C ++的实现,其中当分配

类对象时,其成员函数也在其数据成员的

中分配。这样每个类对象都有一个副本

的所有成员函数。当一个成员函数被调用时,它是对象'的副本,当一个类对象被释放时,

对应的成员函数也被释放。


不要考虑优化或性能,

1.这样的实现是否可行?

2.是否有这样的实现是否符合ISO C ++标准?
Hello. Suppose there is an implementation of C++, in which when a
class object is allocated, its member functions are also allocated in
addition to its data members. So that every class object has a copy
of all of its member functions. When a member function is called, it''s
the object''s copy that When a class object is deallocated, the
corresponding member functions are also deallocated.

Don''t consider optimization or performance,
1. Is such an implementation possible?
2. Does such an implementation conform to the ISO C++ standard?



如果您在类中有一个函数指针,并且从一个类中调用

它是可能的班级成员。取消分配一个类对象,你释放这个

函数指针。


这就是你的想法吗?

This is possible if you have a function pointer in a class, and you call
it from a class member. Deallocating a class object, you deallocate this
function pointer.

Is this what you had on your mind?


这篇关于功能复制可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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