Pointer to a TYPE instance

Previous topic - Next topic


I have a common TYPE (A) that I initialize an instance with values at the program start.
I have another TYPE (B) that has a member of the first TYPE (A).

I want to use my previously initialized instance of (A) in multiple instances of (B).
This works fine automatically when I assign an instance of (A) to the member of an instance of (B).
It just copies the current values from (A).

But if I change values in the source instance of (A), those changes aren't reflected in the instance of (B).
Plus (B) needs as much extra memory as the size of TYPE (A).

What I would love is the ability to declare the member inside TYPE (B) as a pointer to TYPE (A).
That way when I change the instance (A), instances of (B) automatically update.
Plus I don't need the extra memory, just enough to hold the address of instance (A).

Is there a way to do this now?
Even if I have to go INLINE C?
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]


Yes, could with C - something like :

Code (glbasic) Select

class A {

void dummy(void}
class *aA;

aA=new A();

You would have to use classes, of course - and dont forget to free memory too!


Thanks MrTAToad, kinda what I thought.

Gernot, I'm going to get complaints for even suggesting this  >:D, but how hard would it be to add pointers to GLB?
Something like this (and the *TSkin would be a pointer to 'skin' in this case):

Code (glbasic) Select

  skin AS *TSkin
//skin AS TSkin BYREF  << alternate

LOCAL skin AS TSkin
LOCAL gui1 AS TGui
LOCAL gui2 AS TGui
skin.colour = RGB(255,0,0)
gui1.skin = skin
gui2.skin = skin
skin.colour = RGB(0,128,0)  // Now gui1.skin.colour (and gui2) has changed too
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]


Gernot has implied that the chances of pointers being in GLBasic are as remote as Bill Gates working for Apple  :P


I would say Jobs works for Bill Gates as the later has a loooot of apple shares...


Ha, no problem I guess. 
I'll just restructure my code to avoid needing it, by decoupling my Skin and Gui library.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Kitty Hello

You can't store a reference. BUT!
If it's the same and always the very same object, why not make it a global object and use that?


Ya, I decided to move to globals and away from an OOP approach.
It took 2 days but that library is now actually easier to use and read!
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]