结构中的功能指针? [英] Function Pointers in a Structure?

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

问题描述

我已经提到,在标准c中,你可以拥有

结构的行为非常类似于要做某事的类

with结构中的函数调用。


现在,我没有得到详细信息,但有人知道这个人或许正在谈论的是什么吗?关于?你觉得他只是想要功能指针吗?或者我可以像C ++

类一样,调用一个类函数,它可以访问与它相关联的结构,而不包括对它的指针引用。对象为

函数的一个变量?

这将使用Forte 5.0在Sun / Solaris系统上编码,

如果这很重要的话。我不能在这个项目中使用显式C ++

但是如果我可以使用c并使它像C ++那样工作很棒。


Tony

It''s been mentioned to me that, in standard c, that you can have
structures behave very much like classes in relation to something to do
with function calls within a structure.

Now, I didn''t get the details, but does someone have a clue of what
this person perhaps was talking about? Do you think he just ment
something such as function pointers? Or could I, much like a C++
Class, call a class function that has access to the structure it''s
associated with, without including a pointer refrence to the object as
one of the variables of the function?

This will be coded on a Sun/Solaris system using Forte 5.0, by the
way if that''s important. I can''t use explicit C++ with this project
but if I can use c and have it work a lot like C++ that would be great.

Tony

推荐答案

gm * *******@yahoo.com 写道:
我已经提到,在标准c中,你可以拥有
结构表现得很好就像在一个结构中使用函数调用来完成某些事情的类一样。

现在,我没有得到细节,但有人知道什么是
这个人或许在说什么?你觉得他只是想做一些像功能指针这样的东西吗?或者我可以像C ++
类一样调用一个类函数来访问它所关联的结构,而不包括指向对象的指针作为其中一个函数的变量?

这将使用Forte 5.0在Sun / Solaris系统上进行编码,如果这很重要的话。我不能在这个项目中使用显式的C ++
但如果我可以使用c并使它像C ++那样工作很棒。
It''s been mentioned to me that, in standard c, that you can have
structures behave very much like classes in relation to something to do
with function calls within a structure.

Now, I didn''t get the details, but does someone have a clue of what
this person perhaps was talking about? Do you think he just ment
something such as function pointers? Or could I, much like a C++
Class, call a class function that has access to the structure it''s
associated with, without including a pointer refrence to the object as
one of the variables of the function?

This will be coded on a Sun/Solaris system using Forte 5.0, by the
way if that''s important. I can''t use explicit C++ with this project
but if I can use c and have it work a lot like C++ that would be great.




这个人正在谈论结构中的函数指针;

这会为你提供你的类方法。适当的访问宏

可以访问这些方法。稍微更清楚。

您可以通过将父结构

作为第一个成员包含在子结构中来伪造单继承;如果你将一个指针

作为指向祖先的指针访问子结构,那么

仍然有效。以同样的方式你可以通过在孩子中存储另一个函数指针

来有效地覆盖

祖先的父方法。

它通常是一个每个其他类都有一个基类的好主意

来源于;如果你有一个控制字编码

类型的相应类,你有RTTI。

等等。只需在

新闻组档案中查找C语言中的面向对象编程。

干杯

Michael

-

电子邮件:我的是/ at / gmx / dot / de地址。



The person was talking about function pointers in structures;
this gives you your "class methods". Appropriate access macros
can make access to these "methods" slightly clearer.
You can fake single inheritance by including the parent struct
as first member into the child struct; if you access a pointer
to the child struct as a pointer to an ancestor, everything
still works. In much the same way you can effectively overwrite
parent methods of ancestors by storing another function pointer
in the child.
It is usually a good idea to have a base class every other class
is derived from; if you have a control word encoding the type of
the respective class, you have RTTI.
And so on. Just look for object oriented programming in C in the
newsgroups archives.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.


-----开始PGP签名留言 - ---

哈希:SHA1

gm ***** ***@yahoo.com 写道:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

gm********@yahoo.com writes:
我已经提到,在标准c中,你可以拥有
结构表现得很好就像在一个结构中使用函数调用来完成某些事情的类一样。

现在,我没有得到细节,但有人知道什么是
这个人或许在说什么?你觉得他只是想做一些像功能指针这样的东西吗?或者我可以像C ++
类一样调用一个类函数来访问它所关联的结构,而不包括指向对象的指针作为其中一个函数的变量?
It''s been mentioned to me that, in standard c, that you can have
structures behave very much like classes in relation to something to do
with function calls within a structure.

Now, I didn''t get the details, but does someone have a clue of what
this person perhaps was talking about? Do you think he just ment
something such as function pointers? Or could I, much like a C++
Class, call a class function that has access to the structure it''s
associated with, without including a pointer refrence to the object as
one of the variables of the function?



你可以做单继承,虚函数,多态和

RTTI,接口/混合,对象属性和各种OO的东西

in plain C。但是,有些库可以帮助你正确地完成它,

GObject是使用最广泛的东西之一:

http://developer.gnome。 org / doc / API / 2 ... ect / index.html
http://www.le-hacker.org/papers/gobject/

问候,

Roger
< br $> b $ b - -

Roger Leigh

在GNU / Linux上打印? http://gimp-print.sourceforge.net/

Debian GNU / Linux http://www.debian.org/

GPG公钥:0x25BFB848。请签名并加密您的邮件。

----- BEGIN PGP SIGNATURE -----

版本:GnuPG v1.4.1(GNU / Linux)
评论:由Mailcrypt处理3.5.8< http://mailcrypt.sourceforge.net/>


iD8DBQFDDi6PVcFcaSW / uEgRAqunAJ4uBUQYKUx / 7z0pwUxpqVjKKHSGNACgts5W

qIWsX2tQiWYkUwPNaqjnm1I =

= tcwj

----- END PGP SIGNATURE -----



You can do single inheritance, virtual functions, polymorphism and
RTTI, interfaces/mixins, object properties and all sorts of OO stuff
in plain C. However, there are libraries to help you do it properly,
GObject being one of the most widely used:

http://developer.gnome.org/doc/API/2...ect/index.html
http://www.le-hacker.org/papers/gobject/
Regards,
Roger

- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQFDDi6PVcFcaSW/uEgRAqunAJ4uBUqYKUx/7z0pwUxpqVjKKHSGNACgts5W
qIWsX2tQiWYkUwPNaqjnm1I=
=tcwj
-----END PGP SIGNATURE-----


gm********@yahoo.com 于25/08/05写道:
gm********@yahoo.com wrote on 25/08/05 :
我已经提到过,在标准c中,你可以使
结构的行为非常类似于与结构中的函数调用相关的类。


好​​吧,有点......语法是血腥的,因为在C中没有隐含的

''this'...所有都是明确的血淋淋的......

现在,我没有得到细节,但有人知道这个人或许正在谈论什么吗?你觉得他只是想做一些像功能指针这样的东西吗?或者我可以像C ++
类一样调用一个类函数来访问它所关联的结构,而不包括指向对象的指针作为其中一个函数的变量?

这将使用Forte 5.0在Sun / Solaris系统上进行编码,如果这很重要的话。我不能在这个项目中使用显式的C ++
但如果我可以使用c并使它像C ++那样工作很棒。
It''s been mentioned to me that, in standard c, that you can have
structures behave very much like classes in relation to something to do
with function calls within a structure.
Well, sort of... The syntax is gory, because there is no implicit
''this'' in C... All is explicit, thus gory...
Now, I didn''t get the details, but does someone have a clue of what
this person perhaps was talking about? Do you think he just ment
something such as function pointers? Or could I, much like a C++
Class, call a class function that has access to the structure it''s
associated with, without including a pointer refrence to the object as
one of the variables of the function?

This will be coded on a Sun/Solaris system using Forte 5.0, by the
way if that''s important. I can''t use explicit C++ with this project
but if I can use c and have it work a lot like C++ that would be great.




Objective C怎么样?

-

Emmanuel

C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

C库: http://www.dinkumware.com /refxc.html


..sig正在修理



What about Objective C?
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

..sig under repair


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

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