473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

getting a type ID during new operator overloading


Hi, guys,

I need to overload global "new" operator but I have to know the type id
"new" is begin invoked on.
For example if I overload it like this

void *operator new(size_t n)
{
...body...
}

I can only use "n" to get the size of object of whatever type is being
instantiated.
Is it possible to know the type?

thanks in advance

Jul 23 '05 #1
5 1906
<bi********@gmail.com> wrote...
I need to overload global "new" operator but I have to know the type id
"new" is begin invoked on.
Why? Isn't that what class-specific operator new is for?
For example if I overload it like this

void *operator new(size_t n)
{
...body...
}

I can only use "n" to get the size of object of whatever type is being
instantiated.
Is it possible to know the type?


No. Unless, of course, you somehow ensure that all your classes have
different sizes...

V
Jul 23 '05 #2
>Why? Isn't that what class-specific operator new is for?
Class specific operator is no use here. Part of my program uses memory
manager allocating memory by my_new(Type)(...constructor params...) for
example
my_new(int), my_new(MyClass)(123,"123")

But part is just using new. It is too big to go and start changing it
by hand, so I wanted to overload global new.

void *operator new(size_t n)
{
my_new( <type should goes here> )
}

Problem is - I need type.

Jul 23 '05 #3
bi********@gmail.com wrote:
Why? Isn't that what class-specific operator new is for?
Class specific operator is no use here. Part of my program uses memory
manager allocating memory by my_new(Type)(...constructor params...) for
example
my_new(int), my_new(MyClass)(123,"123")


Is this a macro of some kind? Are you implementing memory debugging that
way? There are tools for that, you know...
But part is just using new. It is too big to go and start changing it
by hand,
That's what search-and-replace functionality in modern text editors is
for, isn't it?
so I wanted to overload global new.

void *operator new(size_t n)
{
my_new( <type should goes here> )
}

Problem is - I need type.


Sorry, no such thing available. I believe you're going to be better off
doing the "changing by hand" thing. You need to only do it once, and when
done, you can continue using your macro.

V
Jul 23 '05 #4
Is this a macro of some kind? Are you implementing memory debugging thatway? There are tools for that, you know...
That's what search-and-replace functionality in modern text editors is for, isn't it?


Whatever I am implementing, that was just an example.
Don't try to be a smart ass and spare me your sarcasm. I asked a simple
question. No need to tell me about text editors functionality. Thank
you.

Jul 23 '05 #5
<bi********@gmail.com> wrote...
[...] Thank you.


You're most welcome.
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: NR | last post by:
Hi Folks.. Below is cut paste of one of the "class" in my project... which is used in a composition relationship in many other classes. ----------------------------------------------------...
3
by: CoolPint | last post by:
If I were to design my own container and its iterators, I understand that I need to provide both "iterator" and "const_iterator" so that begin() and end() return appropriate ones depending on the...
16
by: gorda | last post by:
Hello, I am playing around with operator overloading and inheritence, specifically overloading the + operator in the base class and its derived class. The structure is simple: the base class...
6
by: Aaron | last post by:
I'm trying to get an average of a long and a std::vector::size_type, but keep getting 0 for some reason. I've tried the following: float avg = some_long / some_vec.size(); float avg =...
5
by: Fabio Fracassi | last post by:
Hi, I belive what i am trying to do is not possible, but I hope someone can change my mind. Here is some code i'd like to write: template <class type> class engine1 {}; template <class...
67
by: carlos | last post by:
Curious: Why wasnt a primitive exponentiation operator not added to C99? And, are there requests to do so in the next std revision? Justification for doing so: C and C++ are increasingly used...
3
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages...
1
by: Nikhil.S.Ketkar | last post by:
Hi, Does the following construct qualify as overloading on return type ? If not, in what way ? I overloaded the type conversion operator and used pointers to member functions. Its pretty...
1
by: gozlemci | last post by:
Hi everybody; During my coding, I have encountered a problem.I appreciate if anybody answer it. Here is the simplified code: //Header5.h #pragma once #include <string> using namespace std;
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.