![]() |
liv(int) in Liv cannot be applied to () - Java
Compile error:
Code:
liv(int) in Liv cannot be applied to () I initialize the method/function here: Code:
//Opret et objekt af klassen Liv Code:
//Justerer eller returnerer spillerens liv Edit: It works if I call it with the parameter 0. Then I thought it would help initializing the variable in the method, like this: public int liv(int a=0) That just resulted in a bunch of compile errors. |
Re: liv(int) in Liv cannot be applied to () - Java
its logical that you have to pass something to liv(), since you ask for ONE parameter. This would not compile in C either ;)
i think this: Code:
stats_sum = styrke + intelligens + liv.liv()/10; Code:
stats_sum = styrke + intelligens + liv.liv/10; since you want to know the liv as variable, not the function. I dont see any input so i guess you want the liv number... If you want to use the function you should probably do: Code:
stats_sum = styrke + intelligens + liv.liv(0)/10; |
Re: liv(int) in Liv cannot be applied to () - Java
stefan has the answer.
As a more general remark, you shouldn't give the same name to a method and a member variable. This will only cause you more problems like this one in the future. Java coders prefer stuff like getXXX, setXXX, addXXX etc... Also Java and C++ look similar in some places but there are differences, like no default parameters. In C++ you would write: Code:
void foo( int i = 0 ) { ... } Code:
void foo() { foo(0); } Hope this heps. |
Re: liv(int) in Liv cannot be applied to () - Java
Quote:
|
All times are GMT +2. The time now is 12:42. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.