可怕的问题 [英] The dreaded question

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

问题描述

我不在乎它是不是很糟糕的C ++,我真的不喜欢。我需要将

的成员函数指针转换为void *零计算

开销。


我有完美的方法在这里做,但我遇到了麻烦

因为如果我传递给函数的成员函数指针是

没有没有参数的void,我得到一个转换错误。


任何想法怎么做这个?


caustik


// ********************* ***************************** ****************

// *拿这个C ++ !!

// ***************************** ********************* ****************

模板< class BaseClass> ; inline void * MFPtoFP(void

(BaseClass :: * pMemFunc)(void))

{

union

{

void BaseClass :: * pMemFunc;

void * pFunc();

}

ThisConv;


ThisConv.pFunc = pMemFunc;


返回ThisConv.pFunc;

}

I don''t care if its bad C++, I really dont. I need to convert from
a member function pointer to a "void*" with zero computational
overhead.

I have the perfect way to do it right here, but i''m having troubles
because if the member function pointer i pass to the function is
not void with no params, I get a casting error.

Any ideas how to do this?

caustik

// ************************************************** ****************
// * Take THIS C++ !!
// ************************************************** ****************
template <class BaseClass> inline void *MFPtoFP( void
(BaseClass::*pMemFunc)(void) )
{
union
{
void BaseClass::*pMemFunc;
void *pFunc();
}
ThisConv;

ThisConv.pFunc = pMemFunc;

return ThisConv.pFunc;
}

推荐答案

" caustik" < CA ***** @ nospam.com>写道...
"caustik" <ca*****@nospam.com> wrote...
我不在乎它是不是很糟糕的C ++,我真的不喜欢。我需要将
成员函数指针转换为void *。零计算开销。


指向成员的指针无法转换为void *。期。它是'b $ b不是坏C ++,它是不是C ++。这种转换不存在
C ++中的


我有完美的方法在这里做,但我遇到麻烦


所以,如果你遇到麻烦,怎么能完美?

因为如果我传递给函数的成员函数指针是
没有没有参数,我得到一个投射错误。

任何想法如何做到这一点?


没办法。


现在,让我问你一个问题。为什么你认为你需要那个?

caustik

// *********************** *************************** ****************
// *拿这个C ++ !!
// *************************************** *********** ****************
模板< class BaseClass> inline void * MFPtoFP(void
(BaseClass :: * pMemFunc)(void))
{
union
{无效BaseClass :: * pMemFunc;
void * pFunc();


您可以将此声明为


void(* pFunc)();


但是它不会解决转换问题,相信我。

它可能会摆脱投射错误,就像你说的那样,

但是它不会给出正确答案。

}
ThisConv;

ThisConv.pFunc = pMemFunc;

返回ThisConv.pFunc;
}
I don''t care if its bad C++, I really dont. I need to convert from
a member function pointer to a "void*" with zero computational
overhead.
A pointer to member cannot be converted to void*. Period. It''s
not "bad C++", it''s "not C++". Such conversion does not exist
in C++.
I have the perfect way to do it right here, but i''m having troubles
So, if you''re "having troubles", how can it be "perfect"?
because if the member function pointer i pass to the function is
not void with no params, I get a casting error.

Any ideas how to do this?
There is no way.

Now, let me ask you a question. Why do you think you need that?

caustik

// ************************************************** ****************
// * Take THIS C++ !!
// ************************************************** ****************
template <class BaseClass> inline void *MFPtoFP( void
(BaseClass::*pMemFunc)(void) )
{
union
{
void BaseClass::*pMemFunc;
void *pFunc();
You could declare this as

void (*pFunc)();

but it''s _not_ going to solve the conversion problem, trust me.
It will probably get rid of the "casting error", as you put it,
but it''s not going to give the right answer.
}
ThisConv;

ThisConv.pFunc = pMemFunc;

return ThisConv.pFunc;
}




Victor



Victor


" caustik" < CA ***** @ nospam.com>在留言中写道

news:bd ********** @ eeyore.INS.cwru.edu ...
"caustik" <ca*****@nospam.com> wrote in message
news:bd**********@eeyore.INS.cwru.edu...
我不在乎它糟糕的C ++,我真的不喜欢。
I don''t care if its bad C++, I really dont.




那么,我不在乎它是否有效。我真的不喜欢。


大笑


见Victor的回答。


Cy



Well, then, I don''t care if it works. I really don''t.

lol

See Victor''s answer.

Cy


指向成员的指针无法转换为void *。期。它不是糟糕的C ++,而是不是C ++。在C ++中不存在这样的转换。


该死的,你知道我说过我不在乎。有一些技巧,

如果他们在技术上不合法,我就不会给它一个飞行废话。
A pointer to member cannot be converted to void*. Period. It''s
not "bad C++", it''s "not C++". Such conversion does not exist
in C++.
Damn, you know that I stated I dont care. There are tricks to do it,
and I dont give a flying crap if they arent technically legal.
我有完美的方式在这里做,但我有麻烦
I have the perfect way to do it right here, but i''m having troubles



所以,如果你有麻烦,它怎么可能是完美的?



So, if you''re "having troubles", how can it be "perfect"?




好​​吧,傻瓜,这种方法是完美的。因为它在我的程序中100%的时间工作

。我碰巧知道我的程序编译的系统

并执行,所以我可以利用有关该系统的事实。


我想我是无知,敢于优化我的程序。



Well, fool, the method is "perfect" because it works 100% of the time
in my program. I happen to know the system that my program is compiled
and executed on, so I can take advantages of facts about that system.

I suppose I am ignorant to dare to optimize my program.

因为如果我传递给函数的成员函数指针没有没有参数的情况,我得到一个转换错误。 />
任何想法怎么做?
没有办法。
because if the member function pointer i pass to the function is
not void with no params, I get a casting error.

Any ideas how to do this?
There is no way.




废话,我已经做到了。
<现在,让我问你一个问题。为什么你认为你需要它?



Bullshit, I did it already.

Now, let me ask you a question. Why do you think you need that?




让我重新提一下你的问题:为什么你[智能屁股评论]需要这个?


原因是我有大量的函数通用指针,

和它们各自的Wrapper指针。当执行这些截取函数的二进制

代码时调用的函数。问题是这些函数的一些

是__ thiscall,截取的代码必须考虑到这个




信不信由你,不是每个人的C ++程序都可以高效,同时遵守地球上每一个肛门对象导向设计规则。我已经使用已编译的C ++代码连接

,因此它需要一些Hacks。让它有效工作

有效而且看起来不像垃圾。


经过几年阅读这个新闻组,我注意到有一些

排序

与你们中的一些人根深蒂固的心理问题。你很快就会花费30分钟的时间来输入一个冗长的我高于每个人。帖子回复

人们稍微偏离主题或肛门无法回答的问题,而不是

发布一个

的快速解决方案并说注意这个是一个黑客。太可怕了。



Let me rephrase your question: Why do you [smart ass remark] need that?

The reason is that I have a massive array of generic pointers to functions,
and their respective "Wrapper" functions which are called when the binary
code for these intercepted functions is executed. The problem is that some
of these functions are "__thiscall", and the intercepted code must take this
into account.

Believe it or not, not everbody''s C++ program can be efficient while obeying
every single anal object oriented design rule on the planet. I am
interfacing
with already-compiled C++ code, so it takes some "Hacks" to get it working
efficiently and without looking like utter garbage.

After several years of reading this newsgroup, I''ve noticed there is some
sort
of deep rooted psychological problem with some of you guys. You''d sooner
spend 30 minutes typing a lengthy "I''m above everybody" post to respond to
peoples slightly offtopic or anal-incomplatible questions, instead of
posting a
quick solution and saying "note that this is a hack". Its horrible.


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

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