指向委托的函数指针 [英] function pointer to a delegate
问题描述
嗨。
有没有办法在c ++ / cli中有一个指向委托的函数指针
允许我传递具有相同代理的委托签名为
方法的参数?
我正在使用托管代码。假设我们有2个代表:
public delegate void FirstDelegate(int i);
public delegate void SecondDelegate(int i);
classA :: method1()
{
int i = 1;
doSomething();
m_obj-> FirstDelegate(i);
}
A类::方法2()
{
doSomething();
int j = 2;
m_obj-> SecondDelegate(j);
}
有没有办法让一个函数指向一个委托,这样我就可以使用一个公共函数将委托作为一个
参数:
A类:: methodInsteadOf1And2(delegateFunctionPointer)
{
int i = 3 ;
m_obj-> delegateFunctionPointer(i);
}
谢谢,
vcq
Hi.
Is there way to have a function pointer to a delegate in c++/cli that
would allow me to pass delegates with the same signatures as
parameters to a method?
I''m working with managed code. Let''s say we have 2 delegates:
public delegate void FirstDelegate( int i );
public delegate void SecondDelegate( int i );
classA::method1( )
{
int i = 1;
doSomething( );
m_obj->FirstDelegate( i );
}
class A::method2( )
{
doSomething( );
int j = 2;
m_obj->SecondDelegate( j );
}
Is there a way to have a function pointer to a delegate so that I can
just have a common function that would take the delegate as a
parameter:
class A::methodInsteadOf1And2( delegateFunctionPointer )
{
int i = 3;
m_obj->delegateFunctionPointer( i );
}
thanks,
vcq
推荐答案
vcquestions< vc ********* @ gmail.comkirjutas:
vcquestions <vc*********@gmail.comkirjutas:
你好。
有没有办法在c ++ / cli中有一个指向委托的函数指针
允许我传递具有相同代理的代理签名为
方法的参数?
我正在使用托管代码。假设我们有2个代表:
Hi.
Is there way to have a function pointer to a delegate in c++/cli that
would allow me to pass delegates with the same signatures as
parameters to a method?
I''m working with managed code. Let''s say we have 2 delegates:
在C ++中没有委托(也没有托管代码)。你可能会通过在一些MS新闻组或论坛上发帖来获得更好的答案。
在C ++中,你可以形成一个指向类中方法的指针,给定
签名,当实际调用
时,它可以解析为不同的实际方法。我很确定这对你没用,所以我不给你一个
的例子。
问候
Paavo
In C++ there are no delegates (nor managed code). You will probably get
better answers by posting in some MS newsgroups or forums.
In C++, you can form a pointer to a method in a class, with given
signature, which can resolve to different actual methods when actually
called. I am quite sure this is not helpful for you so I don''t give an
example.
Regards
Paavo
Paavo Helde< no **** @ ebi.eekirjutas:
Paavo Helde <no****@ebi.eekirjutas:
vcquestions< vc * ********@gmail.comkirjutas:
vcquestions <vc*********@gmail.comkirjutas:
>嗨。
是否可以使用函数指针c ++ / cli中的委托,
允许我将具有相同签名的代理传递给方法吗?
我正在使用托管代码。假设我们有两个代表:
>Hi.
Is there way to have a function pointer to a delegate in c++/cli that
would allow me to pass delegates with the same signatures as
parameters to a method?
I''m working with managed code. Let''s say we have 2 delegates:
在C ++中没有委托(也没有托管代码)。通过在一些MS新闻组或论坛上发帖,你可能会获得更好的答案。
In C++ there are no delegates (nor managed code). You will probably get
better answers by posting in some MS newsgroups or forums.
哎呀抱歉,混淆了新闻组(再次!)。我们处于一个微观的角色,所以
代表可能是关于话题的。太糟糕我什么都不知道他们
:-(
Paavo
Oops sorry, mixed up the newsgroup (again!). We are in a mircosoft ng, so
delegates are presumably on-topic. Too bad I don''t know anything about them
:-(
Paavo
>
vcquestions写道:
vcquestions wrote:
嗨。
有没有办法在c ++中有一个指向委托的函数指针/ cli
会允许我将具有相同签名的代表传递给方法吗?
我''使用托管代码。假设我们有2个代表:
public delegate void FirstDelegate(int i);
public delegate void SecondDelegate(int i);
Hi.
Is there way to have a function pointer to a delegate in c++/cli that
would allow me to pass delegates with the same signatures as
parameters to a method?
I''m working with managed code. Let''s say we have 2 delegates:
public delegate void FirstDelegate( int i );
public delegate void SecondDelegate( int i );
这是两个具有相同签名的委托类型。
That''s two delegate types with the same signature.
>
classA :: method1()
{
int i = 1;
doSomething();
m_obj-> FirstDelegate(i);
>
classA::method1( )
{
int i = 1;
doSomething( );
m_obj->FirstDelegate( i );
这不起作用,你不能使用带有类型名称的-operator。 />
也许我如果你更加谨慎地区分代表
类型,方法(也就是成员函数)和委托实例,我们将能够
来回答你的问题。
That won''t work, you can''t use the -operator with a type name.
Maybe if you are a little more careful to distinguish between delegate
types, methods (aka member functions), and delegate instances, we''ll be able
to answer your question.
}
A类::方法2()
{
doSomething();
int j = 2;
m_obj-> SecondDelegate(j);
}
有没有办法让一个函数指针给一个委托,这样我就可以使用一个通用的函数将委托作为一个代表作为
参数:
A类:: methodInsteadOf1And2(delegateFunctionPointer)
{
int i = 3;
m_obj-> delegateFunctionPointer(i);
}
谢谢,
vcq
}
class A::method2( )
{
doSomething( );
int j = 2;
m_obj->SecondDelegate( j );
}
Is there a way to have a function pointer to a delegate so that I can
just have a common function that would take the delegate as a
parameter:
class A::methodInsteadOf1And2( delegateFunctionPointer )
{
int i = 3;
m_obj->delegateFunctionPointer( i );
}
thanks,
vcq
这篇关于指向委托的函数指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!