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 5 1923
<bi********@gma il.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
>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. bi********@gmai l.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 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.
<bi********@gma il.com> wrote... [...] Thank you.
You're most welcome. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
----------------------------------------------------
/* class declaration*/
class Packet_serialNo
{
|
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
"constantness" of the container object. I also note that is it done
through overloading begin() and end() like below:
iterator begin();
const_iterator begin() const;
So it seems to me that I need to have two separate iterator classes
|
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 has two int memebers "dataA",
"dataB". The derived class has an additional int member "dataC". I am
simply trying to overload the + operator so that 'adding' two objects
will sum up the corresponding int members.
|
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 = some_long / static_cast<long>(some_vec.size());
Both produce 0. Anyone able to give me a hint at what I'm doing wrong?
|
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 type> class engine2 {};
| |
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 in low-level
numerical computations, replacing Fortran in newer projects.
Check, for example, sourceforge.net or freshmeat.net
But neither language offers a primitive exp operator.
|
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 (Java).
It stores character strings, and resizes itself to accommodate
new strings when needed.
Interface:
----------
|
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 straightforward but I
am sure I have missed as this is not supposed to be possible. Am I
misunderstanding overloading ?
|
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;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |