Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Why these operators cant be overloaded?

Reply
Thread Tools

Why these operators cant be overloaded?

 
 
ambar.shome@gmail.com
Guest
Posts: n/a
 
      08-11-2005
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_cast .

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?

 
Reply With Quote
 
 
 
 
erm
Guest
Posts: n/a
 
      08-11-2005
you can overload operators new and delete

 
Reply With Quote
 
 
 
 
ambar.shome@gmail.com
Guest
Posts: n/a
 
      08-11-2005
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.

 
Reply With Quote
 
Ian
Guest
Posts: n/a
 
      08-11-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
Serge Paccalin
Guest
Posts: n/a
 
      08-11-2005
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
 
Reply With Quote
 
Risto Lankinen
Guest
Posts: n/a
 
      08-11-2005

"Serge Paccalin" <(E-Mail Removed)> wrote in message
news:11oreoy6oimgd$.dlg@canttouchthis-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 -


 
Reply With Quote
 
Maxim Yegorushkin
Guest
Posts: n/a
 
      08-11-2005
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.

 
Reply With Quote
 
ambar.shome@gmail.com
Guest
Posts: n/a
 
      08-11-2005
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_cast .


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?

 
Reply With Quote
 
Risto Lankinen
Guest
Posts: n/a
 
      08-11-2005

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.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_cast .
>
> 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 -


 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      08-11-2005
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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
man i cant belive i cant get help please unclejesse01 DVD Video 2 04-14-2005 03:15 PM
why "." and "->" operators ? C++ 1 06-23-2004 07:45 PM



Advertisments