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.

2 questions:

1. How do you 'wrap' C++ to blitzmax? It's easy with simple functions returning strings or ints or simple data types... but what about classes/objects? how do you do this?

2. How do you get C++ classes and stuff working? and is there such thing as lists in C++?

Here's what i'm trying to do:

C++
#include <string>

using namespace std;

extern "C" {
    class cParticle {
    public:
          float x;
          float y;
          
          void Update(void) {
               x++;
               y++;
          }     
    };
    
    
    cParticle cCreateParticle(void) {
         return new cParticle; // is this right?
    }
    
    void cDeleteParticle(cParticle p) {
         delete p; // is this right?
    }
    
    void cUpdateParticle(cParticle p){
         p.Update(); // what about this one?
    }
    float ParticleX(cParticle p) {
          return p.x;
    }
    float ParticleY(cParticle p) {
          return p.y;
    }
}


and in bmax:

Import "main.cpp"


Extern "C"
	Function cCreateParticle()'What do I return?
	Function cUpdateParticle('What goes in here?)
	Function cDeleteParticle('What goes in here?)
	Function ParticleX:Float('what goes in here?)
	Function ParticleY:Float('what goes in here?)
End Extern

'What data type? 
Local part = cCreateParticle()

Print ParticleX(part)+" , "+ParticleY(part)

cUpdateParticle(part)

Print ParticleX+" , "+ParticleY

cDeleteParticle(part)

Rem
this should print:
0 , 0
1 , 1
End Rem


End