[Java] Can't figure out the error

  1. class Vector2
  2. {
  3.    public Vector2()
  4.    {
  5.       x = 0.f;
  6.       y = 0.f;
  7.    }

  8.    public Vector2(float x, float y)
  9.    {
  10.       this.x = x;
  11.       this.y = y;
  12.    }

  13.    public Vector2 Subtract(Vector2 v2)
  14.    {
  15.      return Vector2((float) this.x - v2.x, (float) this.y - v2.y);
  16.    }


  17.    public float x;
  18.    public float y;
  19. }
複製代碼
The compiler complains about this
pathfinder.java:44: cannot find symbol
symbol  : method Vector2(float,float)
location: class Vector2
     return Vector2((float) this.x - v2.x, (float) this.y - v2.y);
            ^
Note: pathfinder.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

你個OVERLOAD METHOD都冇RETURN野呀...

TOP

原帖由 patrickit 於 2009-9-4 18:14 發表
你個OVERLOAD METHOD都冇RETURN野呀...


Thanks for the reply... but i have wor
return Vector2((float) this.x-v2.x, (float) this.y-v2.y);

Or did you mean the copy constructor has no returned value????

[ 本帖最後由 luckiejacky 於 2009-9-4 18:17 編輯 ]

TOP

public Vector2(float x, float y)
   {
      this.x = x;
      this.y = y;
   }
冇喎...
你用緊邊個METHOD呢?

TOP

原帖由 patrickit 於 2009-9-4 18:19 發表
public Vector2(float x, float y)
   {
      this.x = x;
      this.y = y;
   }
冇喎...
你用緊邊個METHOD呢?


maybe some misunderstanding.... but I am afraid the method we are talking about is the copy constructor ..Thanks in advance

TOP

哎,
你用左邊個METHOD都未知...
please check!
pathfinder.java:44: cannot find symbol
symbol  : method Vector2(float,float)

TOP

原帖由 patrickit 於 2009-9-4 18:24 發表
哎,
你用左邊個METHOD都未知...
please check!
pathfinder.java:44: cannot find symbol
symbol  : method Vector2(float,float)


Ahh... I changed it to public Vector2 Vector2(float x, float y)
it compiles... but copy constructors are not supposed to have returned value....
Correct me if I am wrong
Thanks

TOP

原帖由 luckiejacky 於 2009-9-4 18:28 發表


Ahh... I changed it to public Vector2 Vector2(float x, float y)
it compiles... but copy constructors are not supposed to have returned value....
Correct me if I am wrong
Thanks


public Vector2 Vector2(float x, float y){
....
return something;
}

至於進一步點做, 自己諗下啦

TOP

原帖由 patrickit 於 2009-9-4 18:30 發表


public Vector2 Vector2(float x, float y){
....
return something;
}

至於進一步點做, 自己諗下啦


謝謝

TOP