baffled

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • M

    #1

    baffled

    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 !

  • Michael A. Covington

    #2
    Re: baffled

    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?



    "M" <minnow31@hotma il.com> wrote in message
    news:voudcrk7ma mga8@corp.super news.com...[color=blue]
    > 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 !
    >[/color]


    Comment

    • Peter Rilling

      #3
      Re: baffled

      Maybe I am missing something but you are explicitly saying "location =
      1010". The value "1111" never gets used.

      "M" <minnow31@hotma il.com> wrote in message
      news:voudcrk7ma mga8@corp.super news.com...[color=blue]
      > 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 !
      >[/color]


      Comment

      • M

        #4
        Re: baffled


        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.


        M wrote:
        [color=blue]
        > 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 !
        >[/color]

        Comment

        • M

          #5
          Re: baffled


          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!

          M wrote:
          [color=blue]
          >
          > 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.
          >
          >
          > M wrote:
          >[color=green]
          >> 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 !
          >>[/color]
          >[/color]

          Comment

          • M

            #6
            Re: baffled

            I figured it out.

            Comment

            • bullshark

              #7
              Re: baffled

              On Thu, 16 Oct 2003 20:02:15 -0500, M <minnow31@hotma il.com> wrote:
              [color=blue]
              >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;
              >
              >}[/color]

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

              bullshark

              Comment

              • Hans Kesting

                #8
                Re: baffled


                "M" <minnow31@hotma il.com> wrote in message
                news:voukr3pjl3 9466@corp.super news.com...[color=blue]
                > I figured it out.
                >[/color]

                What was the *real* problem and what was the solution?


                Comment

                Working...