Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Esap1

Will these Variables be changed?

This topic is 6543 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

If I had a function:
    
int LoadFullASE(char *filename, BOOL ShouldLoadTextures,CTextureManager *TextureManager,unsigned int numVertex,unsigned int numFace,	CVertex *Vertex, CFace *Face, float *tu, float *tv);

class CMap
{
public:
unsigned int numVertex;
unsigned int numFace;
CVertex *Vertex;
CFace *Face;
float *tu;
float *tv;
void LoadFile(char *file);
}

void CMap::Loadfile(char *file)
{
LoadFullASE(filename,1,&TextureManager,numVertex,numFace,Vertex,Face,tu,tv);
}
    
Would those Variables in CMap, get changed. Im trying to make them be able to changed by LoadFullASE. Know How?? Thanks yall, later, [source]

Share this post


Link to post
Share on other sites
Advertisement
Yes they will be changed if the LoadFullASE function actually changes them, but you are passing the class''s variables through the function.

=======================================
A man with no head is still a man.
A head with no man is plain freaky.

Share this post


Link to post
Share on other sites
Are you sure, exactly how I wrote it, if The function is changing those Variables, then they will be changed Forever?. It seems that when the function ends, that the variables are the same, 0, even though the function clearly sets them, I dont get it?

Share this post


Link to post
Share on other sites
                
int LoadFullASE(char *filename, BOOL ShouldLoadTextures,CTextureManager *TextureManager,unsigned int numVertex,unsigned int numFace, CVertex *Vertex, CFace *Face, float *tu, float *tv);

[/source]


No. They won't be changed. You'll be able to change the things POINTED by the pointers, but not the pointers themself.

If you want to change them, just add the & operator before each argument you want to change.

If you do :

[source]
void function( int & a, int b)
{
a = 1;
b = 1;
}

void main()
{
int a = 0;
int b = 0;

function( a, b);

cout<<"a:"<<a<<endl;
cout<<"b:"<<b<<endl;
}


You'll get :

a:1
b:0


Edited by - Prosper/LOADED on July 23, 2000 11:33:36 PM

Edited by - Prosper/LOADED on July 23, 2000 11:34:34 PM

Share this post


Link to post
Share on other sites
When I put the & sign, I get a million errors. Whats up. I get errors on the, Face, Vertex, tu, tv. All the ones were they are an Array. How could I change:
void Changer(float *hi)
{
hi[0] = 34;
hi[1] = 32;
}

How would I changed that function and call that function so that hi gets changed?

PS: What the hell does the & sign actually do?

Share this post


Link to post
Share on other sites
The code works for an int value, but what about a pointer to a list of class''s?, how would I do it?

Share this post


Link to post
Share on other sites
um, of course they won''t be changed in your function, when you pass them like...

void blah(int a);

that''s passing the value of whatever

int bigBadInteger=1;
blah(bigBadInteger);

''a'' in blah is going to equal one and has no connection to bigBadInteger.
    
Use..
void blah(int &a);
blah(bigBadInteger);

OR..
void blah(int *a);
blah(&bigBadInteger);



with they way you''re doing, the pointers you''re passing should change though. just not numVertex and numFace unless i misread.

Share this post


Link to post
Share on other sites
btw.. the '&' sign passes a reference or in other words it passes the address of the variable (a pointer to it if that helps it make any more sense).

if you have:
int a;
where address of a == 00000000 (where it's stored in mem)
and the value of a == 10 (the value the variable holds)

a == 10
&a == 00000000
get it?

Edited by - shmaLbus on July 24, 2000 10:57:23 AM

Share this post


Link to post
Share on other sites

  • 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!