Jump to content
  • Advertisement
Sign in to follow this  

Using variables inside an object as locals?

This topic is 4732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, lets say you have this class: class A{ public: float a,b,c; }; And i have the following function: void DoAnything(A *data){ //... } Is there an official way to use the variables in data as local variables: a=0; b=1; c=2; instead of: data->a=0; data->b=1; data->c=2; ? Any help is appreciated. ps. Just to be clear, of course i know i could make it a member function of class A but that's not what i'm looking for :).

Share this post


Link to post
Share on other sites
Advertisement
The only way you could do that (that I can think of) is by making it a member function. Why wouldn't you want to do that?

Share this post


Link to post
Share on other sites
at first glance i'd recommend passing in a ref instead of a pointer...


struct foo { int a, b, c; };

void bar ( foo & f ) {
f.a = 5;
f.b = f.c;
// etc...
}


not what you wanted but a bit more terse and much safer.

Share this post


Link to post
Share on other sites
a freind function will just give you private access. what he is really after i think is making do_anything a member function.

Share this post


Link to post
Share on other sites
Quote:
Original post by DrEvil
friend function?


I can already acces them, i just hoped there was a way to save me some time by accessing them differently.

Quote:
Original post by DrEvila freind function will just give you private access. what he is really after i think is making do_anything a member function.


Well, unfortunately it isn't possible to have a 'shared' member function or anything.


Too bad, thanks anyway.

Share this post


Link to post
Share on other sites
Couldn't you just at the top of the function do this..

float &fA = &object->a;
float &fB = &object->b;

and then access them like normal?

Share this post


Link to post
Share on other sites
Quote:
Original post by segt
Couldn't you just at the top of the function do this..

float &fA = &object->a;
float &fB = &object->b;

and then access them like normal?


Yeah, but still a lot of work, nvm.

Share this post


Link to post
Share on other sites
Got a new question, is it possible to run a thread of a member function? I get the error:

error C2664: '_beginthread' : cannot convert parameter 1 from 'void (__thiscall *)(void *)' to 'void (__cdecl *)(void *)'

Is it possible to typecast that in some way or is it just not possible?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!