问:运营商新/删除的地址 [英] Q: address of operator new/delete

查看:77
本文介绍了问:运营商新/删除的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




是否有可能获得运营商new / delete和运营商

new [] / delete []的地址?否则我将不得不去购买一个非便携式和/或
相当不干净的解决方案。


感谢任何提示!

- -

jb


(如果你想通过电子邮件回复,用x替换y)

Hi,

is it possible to get the address of operator new/delete and operator
new[]/delete[] portably? Otherwise I would have to go for a non-portable and
rather unclean solution.

Thanks for any hints!
--
jb

(replace y with x if you want to reply by e-mail)

推荐答案



" Jakob Bieling" <是ne ***** @ gmy.net>在留言新闻中写道:bj ************* @ news.t-online.com ...

"Jakob Bieling" <ne*****@gmy.net> wrote in message news:bj*************@news.t-online.com...


是不是可以获得运营商新/删除和运营商
new [] / delete []的地址吗?否则我将不得不寻求一种非便携式而且非常不干净的解决方案。
Hi,

is it possible to get the address of operator new/delete and operator
new[]/delete[] portably? Otherwise I would have to go for a non-portable and
rather unclean solution.




#include< new>


using namespace std;


int main(){

void *(* ona)(size_t)=& operator new [];

}



#include <new>

using namespace std;

int main() {
void* (*ona)(size_t) = &operator new[];
}


2003年9月4日星期四17:33:18 +0200,Jakob Bieling < ne ***** @ gmy.net>

写道:
On Thu, 4 Sep 2003 17:33:18 +0200, "Jakob Bieling" <ne*****@gmy.net>
wrote:


是否有可能得到运营商新/删除和运营商的地址
新[] /删除[]可移植?否则我将不得不去寻找一个非便携式且相当不干净的解决方案。
Hi,

is it possible to get the address of operator new/delete and operator
new[]/delete[] portably? Otherwise I would have to go for a non-portable and
rather unclean solution.




AFAIK,这是好的和便携的:


#include< cstddef>

#include< new>


struct A

{

void * operator new(size_t)

{

throw std :: bad_alloc();

}

};


int main()

{

void *(* ptr1)(std: :size_t)= :: operator new;

void *(* ptr2)(std :: size_t)=& A :: operator new;

}


Tom



AFAIK, this is fine and portable:

#include <cstddef>
#include <new>

struct A
{
void* operator new(size_t)
{
throw std::bad_alloc();
}
};

int main()
{
void* (*ptr1)(std::size_t) = ::operator new;
void* (*ptr2)(std::size_t) = &A::operator new;
}

Tom


" Ron Natalie" < ro*@sensor.com>在留言中写道

新闻:3f *********************** @ news.newshosting.co m ...
"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f***********************@news.newshosting.co m...

Jakob Bieling <是ne ***** @ gmy.net>在消息中写道

"Jakob Bieling" <ne*****@gmy.net> wrote in message



新闻:bj ************* @ news.t-online.com ...


news:bj*************@news.t-online.com...



是否有可能获得operator new / delete和
operator new [] / delete []的地址?否则我将不得不寻找一个非便携的
而不是不干净的解决方案。
Hi,

is it possible to get the address of operator new/delete and operator new[]/delete[] portably? Otherwise I would have to go for a non-portable and rather unclean solution.



#include< new>

使用命名空间std;

int main(){
void *(* ona)(size_t)=& operator new [];
}



#include <new>

using namespace std;

int main() {
void* (*ona)(size_t) = &operator new[];
}



哦,我明白了。我试图将它直接转换为void *并且我不知道
知道哪个超载了我想要的运营商地址。使用static_cast它现在可以使用



谢谢!

-

jb


(如果你想通过电子邮件回复,用x替换y)


Oh I see. I tried to convert it to a void* directly and I prolly did not
know which overloaded operator''s address I wanted. With a static_cast it
works now.

Thanks!
--
jb

(replace y with x if you want to reply by e-mail)


这篇关于问:运营商新/删除的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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