获取在操作符new中分配的对象类型 [英] Get type of object being allocated in operator new

查看:148
本文介绍了获取在操作符new中分配的对象类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法获取在操作符new中分配的对象类型?

Is there a way to get type of object being allocated in operator new?

我的意思是:

void* BaseClass::operator new(size_t size)
{
    void* result = ::operator new(size);

    //Get type of object that's being allocated

    return result;
}


推荐答案

这个数据。 operator new 只是在给定大小的情况下分配原始内存,只有 new 操作符调用知道构造对象的类型分配的内存。

There is no mechanism to get this data. operator new just allocates raw memory given a size, and only the new operator call knows the type to construct the object into the allocated memory.

这篇关于获取在操作符new中分配的对象类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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