Advertisement

Madness?

Started by October 04, 2000 04:50 AM
13 comments, last by wise_Guy 24 years, 3 months ago
Okay, all_powerups is a double pointer.

object **all_powerups;

but I have typedef 'd object_pointer to be a pointer to an object, so isn't that the same as what you suggested?

Anyway, i'm still wondering how a member function is attached to the class... it shouldn't be saved in each one should it? because all instances of powerup use the same function...

It was suggested that I need to assign a pointer to this function but is this necessery and how do I do it?




Edited by - wise_guy on October 5, 2000 9:33:44 PM
quote:
Okay, all_powerups is a double pointer.

object **all_powerups;

but I have typedef ''d object_pointer to be a pointer to an object, so isn''t that the same as what you suggested?

Anyway, i''m still wondering how a member function is attached to the class... it shouldn''t be saved in each one should it? because all instances of powerup use the same function...

It was suggested that I need to assign a pointer to this function but is this necessery and how do I do it?


As far as I know, member functions aren''t saved in each object, only member variables are (Of course).
Try if this works for you:

    all_powerups = new object_pointer*[num_powerups];for (j=0 ; j<num_powerups ; j++){all_powerups[j] = new powerup;fread(all_powerups[j], sizeof(powerup), 1, file);all_powerups[j]->sprite = power_sprites;}    


About your second question, you want to make a function pointer?
Let''s say your first function is:

int SomeFunc(int x); // for example

Your function pointer will be:

int (*SomeFuncPointer)(int x);

Now if you want SomeFuncPointer to point at SomeFunc you simply do:

SomeFuncPointer = SomeFunc;

That''s what you wanted?
Goblineye EntertainmentThe road to success is always under construction
Advertisement
Okay, I know that I don''t need to do this...

(1) all_powerups = new object*[num_powerups];
or
(2) all_powerups = new object_pointer*[num_powerups];

Because I tried that and (1) gives me the same error that I
normally get (because it is the same as using a typedef), and
(2) gives a compiler error because in effect it is the same
as writing

all_powerups = new object**[num_powerups];

Seeing as all the member values get loaded correctly, I don''t
think that there are errors in the initialisation code. Could
I be writing over the VTABLE? Actually that could be it! but how
to fix it.... don''t tell me I need to save every variable
seperately.... no there has to be another way...

wise_guy
Why not write two function that read and writes out the data in the class Powerup or whatever, and call them inside the loop. That should work, cos I do it all the time. No problems!

------------------------------
BCB DX Library - RAD C++ Game development for BCB
Okay, c++freak, so you mean write out a function to save each
variable to the file, one by one...

I suppose I can do that.......

...but I wish there was another way...

wise_guy

This topic is closed to new replies.

Advertisement