C++

Miscellaneous Forums/General Discussion/C++

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I'm not sure about wrapping to BlitzMax, but the C++ code has some problems:
    cParticle cCreateParticle(void) {
         return new cParticle; // is this right?
    }
    
    void cDeleteParticle(cParticle p) {
         delete p; // is this right?
    }


In C++ you can pass by value (which copies the object), or by reference or pointer. Here you're passing and returning a copy of the object, which is not right. cDeleteParticle() is going to copy the object, then delete it, which actually does nothing to the original object (in fact it may even crash because you can't delete an object that you didn't create with "new").

Here's how it should be:
    cParticle *cCreateParticle(void) {
         return new cParticle;
    }
    
    void cDeleteParticle(cParticle *p) {
         delete p;
    }


BlitzMax uses a garbage collection system, so everything is basically a pointer, but in C++ you need to make the distinction between passing pointers or passing a copy of the whole object.