我可以写一个递归类型定义吗? [英] Can I write a recursive type definition ?

查看:65
本文介绍了我可以写一个递归类型定义吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[交叉发布到:comp.lang.c,comp.lang.c ++]


你好所有


我''我面临一个非常奇怪的问题。我需要定义一个函数,它将

参数视为指向自身的指针。它需要一个与指针相同类型的指针

作为参数,并且可能还有其他的指向函数的指针。但是我没有这样一个指针的数据类型

因为函数原型同时被定义了。我希望你

跟着我...


Actualy我需要定义一个指向函数的指针。我的

应用程序的不同模块将安装一个由该指针指向的新函数,并且每个新的

函数将记住该地址并调用前一个函数,

形成仅存在于代码中的链。我想这个想法用于库中的

at_exit()函数或类似的东西。


现在我希望函数将参数作为参数指针另一个

的实例是相同的函数类型。这将允许从

链中删除函数,即使是与安装的函数不同的顺序,

每个已安装的函数都会识别它自己的地址。参数

然后返回它之前已知道的安装函数


我希望你跟着我...


那么我怎么能声明一个函数的原型作为参数

并返回一个指向同一函数类型的指针?


谢谢

Timothy Madden

罗马尼亚

----------------- ---------------------------------

而且我不想错过事情

[Cross-posted to: comp.lang.c, comp.lang.c++]

Hello all

I''m facing a very strange problem. I need to define a function that takes as
argument something like a pointer to itself. It takes as argument a pointer
of the same type as a pointer to itself and with possibly other
pointer-to-function value. But I don''t have a data type for such a pointer
because the function prototype is in the same time being defined. I hope you
are following me ...

Actualy I need to define a pointer to a function. Different modules of my
app will install a new function to be pointed by this pointer, and each new
function will remember the address of and call the previous function,
forming a chain that exists only in code. I guess the idea is used for
at_exit() function in the library or something like it.

Now I want the function to take as argument a pointer to another instance of
the same function type. This will allow for removing functions from the
chain even in a different order than the one functions were installed, by
having each installed function recognize it''s own address in the argument
and then return as a result the previous installed function that it knows of

I hope you are following me...

So how could I declare the prototype for a function that takes as argument
and that returns a pointer to the same function type being declared ?

Thank you
Timothy Madden
Romania
--------------------------------------------------
And I don''t wanna miss a thing

推荐答案



" Timothy Madden" < BA **** @ rmv.spam.home.ro>在消息中写道

新闻:2s ************* @ uni-berlin.de ...

"Timothy Madden" <ba****@rmv.spam.home.ro> wrote in message
news:2s*************@uni-berlin.de...
[交叉发布到: comp.lang.c,comp.lang.c ++]

大家好。

我正面临一个非常奇怪的问题。我需要定义一个函数,它将
作为参数,类似于指向自身的指针。它将一个
指针作为参数作为一个指向自身的指针,并且可能还有其他指针到函数的值。但我没有这种指针的数据类型
因为函数原型正在定义中。我希望
你跟着我...

Actualy我需要定义一个指向函数的指针。我的
应用程序的不同模块将安装一个由此指针指向的新函数,并且每个
新函数将记住地址并调用前一个函数,
形成仅存在的链在代码中。我想这个想法用于库中的
at_exit()函数或类似的东西。

现在我希望函数将参数作为参数指向另一个实例
of相同的功能类型。这将允许从
链中删除功能,即使是与安装的功能不同的顺序,通过每个安装的功能在参数中识别它自己的地址
然后返回结果是之前安装的函数,它知道

我希望你跟着我...

那我怎么能声明一个函数的原型参数
并返回一个指向同一函数类型的指针?

谢谢
Timothy Madden
罗马尼亚
------- -------------------------------------------
我不知道我想错过一件事
[Cross-posted to: comp.lang.c, comp.lang.c++]

Hello all

I''m facing a very strange problem. I need to define a function that takes as argument something like a pointer to itself. It takes as argument a pointer of the same type as a pointer to itself and with possibly other
pointer-to-function value. But I don''t have a data type for such a pointer
because the function prototype is in the same time being defined. I hope you are following me ...

Actualy I need to define a pointer to a function. Different modules of my
app will install a new function to be pointed by this pointer, and each new function will remember the address of and call the previous function,
forming a chain that exists only in code. I guess the idea is used for
at_exit() function in the library or something like it.

Now I want the function to take as argument a pointer to another instance of the same function type. This will allow for removing functions from the
chain even in a different order than the one functions were installed, by
having each installed function recognize it''s own address in the argument
and then return as a result the previous installed function that it knows of
I hope you are following me...

So how could I declare the prototype for a function that takes as argument
and that returns a pointer to the same function type being declared ?

Thank you
Timothy Madden
Romania
--------------------------------------------------
And I don''t wanna miss a thing




我相信它会告诉你如何处理这个问题。

问候。



I believe that it tells you how to handle this in the FAQ.
Regards.


" Timothy Madden" < BA **** @ rmv.spam.home.ro>在留言新闻中写道:< 2s ************* @ uni-berlin.de> ...

[snip]
"Timothy Madden" <ba****@rmv.spam.home.ro> wrote in message news:<2s*************@uni-berlin.de>...
[snip]
但是我没有这种指针的数据类型
因为函数原型在同一时间被定义。
But I don''t have a data type for such a pointer
because the function prototype is in the same time being defined.




你想要一个函数它将一个指向函数的指针作为参数,

它将一个指向函数的指针作为参数,它将一个指向一个函数的指针作为参数。


我不确定你能不能做到。我不确定你不能这样做。但是

它让我头晕目眩。


我想如果定义一个功能性的话你可能会更好

成员的一个类,然后有一个数据成员指向

适当的其他类实例。

袜子



You want a function that takes as argument a pointer to a function,
which takes as argument a pointer to a function, which takes as
argument a pointer to a function, which ...

I''m not sure you can do it. I''m not sure you can''t do it. But
it''s making me dizzy.

I think you''d probably be better off if you defined a functional
member of a class and then had a data member that pointed to the
appropriate other instance of the class.
Socks


" Timothy Madden" < BA **** @ rmv.spam.home.ro>在消息中写道
"Timothy Madden" <ba****@rmv.spam.home.ro> wrote in message
我正面临着一个非常奇怪的问题。我需要定义一个函数,它将
作为参数,类似于指向自身的指针。它将一个
指针作为参数作为一个指向自身的指针,并且可能还有其他指针到函数的值。但我没有这种指针的数据类型
因为函数原型正在定义中。我希望
你跟着我......


你有一个数组/向量/堆栈的函数指针或对象或者

指向一个abstrat类对象?当你想要执行数组时,你需要逐步执行每个元素并执行每个元素。因此,而不是我的应用程序的不同模块将安装一个新函数来指向

这个指针,每个新函数都会记住地址并调用

上一个函数,你会插入新的函数指针或对象,或者把对象指向对象的数据。


如果你真的想调用一个返回一个函数的函数,我认为你可以设置一个类层次结构并调用一个类成员函数

返回一个新类,这个新类存储了一个指向原始

类的指针。

Actualy我需要定义一个指向函数的指针。我的
应用程序的不同模块将安装一个由此指针指向的新函数,并且每个
新函数将记住地址并调用前一个函数,
形成仅存在的链在代码中。我想这个想法用于库中的
at_exit()函数或类似的东西。

现在我希望函数将参数作为参数指向另一个实例
of相同的功能类型。这将允许从
链中删除功能,即使是与安装的功能不同的顺序,通过每个安装的功能在参数中识别它自己的地址
然后返回结果是之前安装的函数,它知道

我希望你跟着我...

那我怎么能声明一个函数的原型参数
并返回一个指向同一函数类型的指针?
I''m facing a very strange problem. I need to define a function that takes as argument something like a pointer to itself. It takes as argument a pointer of the same type as a pointer to itself and with possibly other
pointer-to-function value. But I don''t have a data type for such a pointer
because the function prototype is in the same time being defined. I hope you are following me ...
Could you have an array/vector/stack of function pointers or objects or
pointers to an abstrat class object? When you want to execute the array,
you step through each element and execute each one. So rather than
"different modules of my app will install a new function to be pointed by
this pointer, and each new function will remember the address of and call
the previous function", you''ll insert new function pointers or objects or
pointers to objects into the array.

If you literally want to call a function that returns a function, I think
you can setup a class hierarchy and call a class member function that
returns a new class, and this new class stores a pointer to the original
class.
Actualy I need to define a pointer to a function. Different modules of my
app will install a new function to be pointed by this pointer, and each new function will remember the address of and call the previous function,
forming a chain that exists only in code. I guess the idea is used for
at_exit() function in the library or something like it.

Now I want the function to take as argument a pointer to another instance of the same function type. This will allow for removing functions from the
chain even in a different order than the one functions were installed, by
having each installed function recognize it''s own address in the argument
and then return as a result the previous installed function that it knows of
I hope you are following me...

So how could I declare the prototype for a function that takes as argument
and that returns a pointer to the same function type being declared ?






这篇关于我可以写一个递归类型定义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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