Hi,
As you know there are few operators in C++ which cant be overloaded.
They are:
.., .*, ::, ?: , new , delete , sizeof , typeid , static_casr ,
dynamic_cast , const_cast , reinterpret_cas t .
Theremust be some reason for this restriction for each of the
operators.
Does anyone know the exact reason for such restriction on each of them? 14 3662
you can overload operators new and delete
I dont think "new" can be overloaded. "operator new" can be overloaded
but not "new" operator. Same for delete. Follow any traditional book
for confirmation. am*********@gma il.com wrote: I dont think "new" can be overloaded. "operator new" can be overloaded but not "new" operator. Same for delete. Follow any traditional book for confirmation.
And the difference is?
You can have your own class local operator new and your own global one.
Ian
Le jeudi 11 août 2005 à 10:33, Ian a écrit dans comp.lang.c++*: I dont think "new" can be overloaded. "operator new" can be overloaded but not "new" operator. Same for delete. Follow any traditional book for confirmation. And the difference is?
The new operator first calls operator new() and then the constructor(s).
--
___________ 11/08/2005 10:37:58
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Il faut donc que les hommes commencent
-'(__) par n'être pas fanatiques pour mériter
_/___(_) la tolérance. -- Voltaire, 1763
"Serge Paccalin" <sp@mailclub.no .spam.net.inval id> wrote in message
news:11******** ********@cantto uchthis-127.0.0.1... Le jeudi 11 août 2005 à 10:33, Ian a écrit dans comp.lang.c++ :
I dont think "new" can be overloaded. "operator new" can be overloaded but not "new" operator. Same for delete. Follow any traditional book for confirmation. And the difference is?
The new operator first calls operator new() and then the constructor(s).
Very artificial distinction.
Or, similarly it could be argued that "->" operator cannot be overloaded,
but "operator->" can (because the "->" operator first calls "operator->"
and then the "->" operator).
- Risto -
Serge Paccalin wrote: Le jeudi 11 août 2005 à 10:33, Ian a écrit dans comp.lang.c++ :
I dont think "new" can be overloaded. "operator new" can be overloaded but not "new" operator. Same for delete. Follow any traditional book for confirmation. And the difference is?
The new operator first calls operator new() and then the constructor(s).
There are new statement and operator new (the same applies to delete).
new statement is a language construct that calls operator new and then
an object constructor. new statement can not be redefined or overloaded
(macro aside), but operator new can be overloaded.
The same name for language construct and operator has lead to much
confusion.
Hi,
I think you all are not following my original question. Once again
please follow my query given below:
---------------------------------------------------------------------------------------------------------------------------------
As you know there are few operators in C++ which cant be overloaded.
They are:
.., .*, ::, ?: , new , delete , sizeof , typeid , static_casr ,
dynamic_cast , const_cast , reinterpret_cas t .
Theremust be some reason for this restriction for each of the
operators.
Does anyone know the exact reason for such restriction on each of them?
----------------------------------------------------------------------------------------------------------------------------
I am desperately looking for answer . Will anybody help me on this?
<am*********@gm ail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. . As you know there are few operators in C++ which cant be overloaded.
., .*, ::, ?: , new , delete , sizeof , typeid , static_casr , dynamic_cast , const_cast , reinterpret_cas t .
Theremust be some reason for this restriction for each of the operators.
Does anyone know the exact reason for such restriction on each of them? http://www.research.att.com/~bs/bs_f...l#overload-dot
- Risto -
erm wrote: you can overload operators new and delete
Well, yes and no. You can overload operator new and operator delete, but
you cannot overload the new and delete operators, which was what the
original question was about.
operator new and operator delete are functions: void *operator
new(size_t) and void operator delete(void*) in their simplest forms.
When you say 'new int' you're using the new operator to create an int on
the heap; it calls operator new to get the memory, then constructs the
value as appropriate for the type. Similarly, when you say 'delete ptr'
you're using the delete operator, which destroys the value and then
calls operator delete to release the memory.
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andy Jarrell |
last post by:
I'm trying to inherit from a specific class that has an overloaded operator. The problem I'm getting is that certain
overloaded operators don't seem to come with the inheritance. For example:
// TestA.h ---------------------------------------
#include <iostream>
enum Aval
{
FIRST_VALUE,
|
by: Nimmi Srivastav |
last post by:
There's a rather nondescript book called "Using Borland C++" by Lee
and Mark Atkinson (Que Corporation) which presents an excellent
discussion of overloaded new and delete operators.
I am presenting below a summary of what I have gathered. I would
appreciate if someone could point out to something that is specific to
Borland C++ and is not supported by the ANSI standard. I am also
concerned that some of the information may be outdated...
|
by: Brad Eck |
last post by:
"The only operators that cannot be overloaded
are :: (scope resolution), . (member selection), and .* (member
selection through pointer to function). Quoting from Stroustrup's 3rd
edition of _The C++ Programming Language_, section 11.2 (page 263),
these three operators 'take a name, rather than a value, as their
second operand and provide the primary means of referring to members.
Allowing them to be overloaded would lead to subtleties.'"...
|
by: masood.iqbal |
last post by:
Please help me with this doubt that I have regarding overloaded
operators. Sometimes they are member functions and sometimes they are
friends (e.g. see the code snippet from Stroustrup, Second Edition that
I have posted to comp.sources.d). How do we decide which is more
appropriate? Why are the overloaded "<<" and ">>" operators always
friends?
Also, what is an appropriate application for the overloaded function
call operator?
|
by: maadhuu |
last post by:
hi
i wasnt to know the answer for the following.
now ,u can overload all the operators which are basically determined at
runtime (coz' of whch operators like sizeof())cannot be overloaded.
now my doubt is , if u have something like
p->a ....where p(say) is a pointer of a user defined type, then u can
overload this because p is determined at runtime ???is this right ???
also if "a" is an object of the some user defined class,
| |
by: Syanide |
last post by:
here's a bit info for you fellas:
eg.. you have Square classes u wanna add
public static int operator+ (Square s1, Square s2)
{
// your code here
}
comparision operators..
|
by: Silver Phoenix |
last post by:
Greetings.
I have some questions that I would like to clear out.
1. Why do operators have to be static? (This question relates to the
language specification)
2. More importantly, couldn't there be operators that were tranlated at
compile-time to "normal" methods?
|
by: Suman |
last post by:
Having had a look at the C++ FAQ, comp.lang.c++ & comp.std.c++
archives and Stroustrup's FAQs (particularly the following:
<url:http://www.research.att.com/~bs/bs_faq2.html#overload-dot/>)
I am left to wondering why Stroustrup doesn't mention the
*_cast<> operators or operator .* in that particular FAQ.
Archived discussions have convinced me that .* _cannot_ be overloaded.
I have gathered a notion (perhaps incorrectly) that the *_cast<>...
|
by: velvizhi |
last post by:
why the operators like scope resolution operator,conditional operator,size of operator cant be overloaded?
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
| |