OOP quick tuto +1 bug.

Previous topic - Next topic

sf-in-sf

Code (glbasic) Select

// --------------------------------- //
// Project: objtestA0
// Start: Thursday, November 29, 2012
// IDE Version: 10.244


// SETCURRENTDIR("Media") // go to media files
SETSCREEN 400,400,0
LIMITFPS 25
mymain() // call your own 'main Function' here.



//____________________________________
// quit GLb's main function like this:
FUNCTION foo:
// keep it empty.
ENDFUNCTION



//LOCAL z%
// this 'z' declaration doesn't work here any more,
// because it's outside a function.
INLINE

class Koto{
public:
int fish;
Koto(){}; // constructor
~Koto(){}; // destructor
void ppprint()
{ for (int z=3; z<=13; z++)
{ PRINT( z, 30+2*z,25*z);
PRINT( z+2, 60+2*z,25*z);
}

// F***
// // //ENDINLIN* // ADDING THE 'E' => ERROR.
// although it's printed in yellow like a comment.
// it's a 7-leg bug.
// INLINE ... is ignored properly.

/*
F***
other out-comments work o.k. otherwise.
*/

};
protected:
private: // ad libitum

};
ENDINLINE




FUNCTION mymain:
INLINE
Koto k; // instanciation.
k.ppprint(); // run the Fn.
ENDINLINE

SHOWSCREEN
MOUSEWAIT // please click to quit.
END

ENDFUNCTION // it works fine.

On the day the atom is a cube I will start believing in the square pixel.

Hemlos

interesting

im not too familliar with c++ classes and inheritance

how would you do something like this

FUNCTION mymain:
   INLINE
      Koto k; // instanciation.
      j=k;
      j.ppprint(); // run the Fn.
   ENDINLINE
Bing ChatGpt is pretty smart :O

sf-in-sf

Normally, this doesn't copy the object. only the k reference gets copied. no j object is created. using j should act on the k object. Try and see.
On the day the atom is a cube I will start believing in the square pixel.

mentalthink

Very interesting I do the "clases" directly from GLbasic, but in C++ I think can be more powerfully... thanks because it's something I want learn from a long time ago... very very instructive...

Regards,