Skip to main content
GameDev.net gamedev.net
🔒 Locked

What does this code do?

Started by Tyson Apr 21, 2003 at 4:07 PM 5 replies 900+ views
Original Post
Tyson
Tyson
I was just wondering if anyone could tell me what the "Parent::operator delete;" line does in the following:
  
template <class T,class Alloc> class TMListImp :
    private TMListBlockInitializer<T,Alloc>
{

    typedef TMListBlockInitializer<T,Alloc> Parent;

....

    void ForEach( IterFunc iter, void *args );
    T *FirstThat( CondFunc cond, void *args ) const;
    T *LastThat( CondFunc cond, void *args ) const;

    Parent::operator delete;

...
};
   
The Parent::operator delete line is not in a function, so I am confused as to what it's purpose is and what it is used for. Also, I am wondering what the typedef for parent really does. Is this some method of inserting a type into another's scope? Thanks in advance! --Voxel [edited by - tyson on April 21, 2003 5:08:55 PM]
============================A guy, some jolt, and a whole lot of code :)
civguy
civguy
I've seen the same being used like this:

    
using Parent::operator delete;

But I guess that does the same thing. What it does is expose the static delete operator from the *private* base class (TMListBlockInitializer) to the subclass (TMListImp). So without it, you wouldn't have access to TMListBlockInitializer's delete operator.

The typedef is there for convenience. No need to type "TMListBlockInitializer<T,Alloc>" every time you want to refer to the base class. It's also within TMListImp's scope so it won't pollute the outer namespace.

Eg.
TMListImp<int, Allocator>:: Parent
gives you TMListImp's base class without even knowing what it's real type is.

[edited by - civguy on April 21, 2003 5:19:57 PM]
Tyson
Tyson
Thanks the reply civguy! That makes sense. That is makes the operator visible, but what is the purpose of:

Parent::operator delete;

It looks like a call, but it isn''t. Is it simply a re-declaration of that opertator for some reason?

Thanks,

Tyson
============================A guy, some jolt, and a whole lot of code :)
civguy
civguy
quote:
Original post by Tyson
Is it simply a re-declaration of that opertator for some reason?
It''s called an access declaration. It''s pretty rarely seen so I had to look it up from the grammar. And the grammar also had this to say: "Access declarations are deprecated; member using-declarations (7.3.3) provide a better means of doing the same things."

So "using Parent::operator delete;" would be the ''correct'' way to do it these days.
Shannon Barber
Shannon Barber
Adding the using clause changes the method's access protection and will bring in a family of overloaded methods after you've shadowed it with an override (perhaps more things I've forgotten?).

That code as posted [looks like] a forward declare (prototype if you're accustom to the old C term) - because of the templates, the compiler might not be able to know ahead of time that the operator delete is overloaded in the parent class so it needs to be told. Usually that's needed with the Curriously Recurring Template Idiom wherein you inherit from the class passed in as a template parameter - but that does [not] appear to be in use here.

Notice that TMListImp inherits privately from TMListBlockInitializer, so the overloaded delete needs to be brought into public scope in order for it to be invoked (otherwise it's a compile error, operator delete is private).

It must be a bug, the using clause is missing.

[edited by - Magmai Kai Holmlor on April 21, 2003 6:02:09 PM]
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Tyson
Tyson
The funny thing is that is straight from a Borland Header for thier OWL libraries. It compiles great under BC++ 5.02 but while converting a project over to Builder 6 I am having some compile issues with this code. I just could not find out what the heck that did!

PS: The compile Error I am getting is something to do with class membership (I can''t remember the exact error as that damnable peice of code is at work). Now that I know what that is doing, I think I can correct the problem. Thanks everyone!
============================A guy, some jolt, and a whole lot of code :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.