Design speed and reusability: c vs. c++

Started by
33 comments, last by Succinct 22 years, 5 months ago
quote:
Dont delete call the destructor automatically??
Why do this.... myClass->~mYClass()???

It''s a special case for when you use placement new (which is how you construct an object in RAM allocated by malloc)

Magmai Kai Holmlor
- Not For Rent
- 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
Advertisement
You shouldn''t use malloc on classes cause it may fail if there are inheritance and other C++ things.

The new does a lot of things than malloc.
quote:Original post by Void
You shouldn't use malloc on classes cause it may fail if there are inheritance and other C++ things.

The new does a lot of things than malloc.

Not really, new allocates memory, then calls the constructor. The constructor is the piece of code responsible for setting up the object properly. This includes calling the constructors of base-classes, initializing the v-table if appropriate, etc. All the code to do this is automatically inserted by the compiler in every constructor.

So allocating memory with malloc, and then using placement-new to construct it is perfectly valid (in fact that's the whole point of having a placement-new).

Even if I'm wrong and new does do other things as well, then placement-new will still do it for you.

I know, this is very off-topic. Sorry.

Edited by - Dactylos on November 7, 2001 10:21:48 PM
Hey, i for myself had the same problems at work, what i simply did is to stick with the "local policies", what you do at work is simply to make the boss make more cash, from what i have read dont fall into the traps of making like the other programmers though. Do not "slop" your code, one thing of the outmost importance is to make sure you can be in the feet of another coder who would work with your stuff. Remember that if you would ever go work somewhere else, they will surely miss the fact that everything you have done is "WELL" coded and "UNDERSTANDABLE". I dont know how much time i wasted working on poorly written software trying to figure out what the guy was thinking about back then ! Comment your code also ( im sure you already do it). But what do you know there is sooooooo much hot headed ultra-hot-headed-optimized-holier-than-thou coders in this world that 90% of these peeps forget these basic rules. sorry it was too much to retain to myself . Remember code Object oriented it is THE EVOLUTION.

May the code be with us !
May the code be with us !
oh , btw nice to see that ppl can get easily a job, i have a paper since last may and ive been thrown out of a company last october ( project fund problems), its really hard to get a job for a programmer here in canada, even with good college education they ask for ppl with 2-3 year exp. or university. Im a bit desperate to become only junior, but it seems too much to ask. Hell i did a motion-tracking software wich 3 other ppl where not able to do .... me think not me the problem. Sorry the lack of money is making me crazy...

May the code be with us !
May the code be with us !

This topic is closed to new replies.

Advertisement