baffled

  • Thread starter Thread starter M
  • Start date Start date
M

M

I have a class with a constructor:

public nerd(int userId, int locNo, int divNo)
{

location = 1010;

}

If I call a method/func that uses the above, like so:

public nerd myMethod(1,1111, 0)

the return object shows a location value of 1010, not 1111!

Why is this?

Thank you !
 
Because you are setting location to 1010? I see no indication that it
should ever be anything else.

Maybe the real story is more complicated?
 
Maybe I am missing something but you are explicitly saying "location =
1010". The value "1111" never gets used.
 
oops.

I should have said
public nerd(int userId, int locNo, int divNo)
{

location = locNo;

}

I'm still working on this, help is very much appreciated!
Sorry for the confusion.
 
Um, I still didn't write this out correctly.

My code only calls the "new" nerd to instantiate a nerd object within
the myMethod function. When I return the nerd from MyMethod, upon
examination, no values have been changed. This function works fine,
EXCEPT now that I have a constructor in the nerd class, MyMethod no
longer writes values the way I think it should.

A little more code to show what I am talking about:

public nerd MyMethod(int userId, int locNo, int divNo)
{
nerd myNerd = new nerd(userId, 1010, divNo) //this should call the
constructor which sets the location property to 1010.

nerd.location = 1111;
return nerd;

}

BUT...when I examine the nerd object, nerd.location = 1010!
 
public nerd MyMethod(int userId, int locNo, int divNo)
{
nerd myNerd = new nerd(userId, 1010, divNo) //this should call the
constructor which sets the location property to 1010.

nerd.location = 1111;
return nerd;

}

Does that even compile?
How about trying :
myNerd.location=1111;
return myNerd;

bullshark
 
Back
Top