Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
It's used to refer to objects that are specific to that method. Since different classes can override methods, the use of "this" basically eleminated confusion between classes that have the same parameter.
So for example, two methods may both have int x but using "this.x", you can specify that it's this x for this specific method.
If you have a good understanding of method overriding then this would be more understandable. I hope I cleared up some confusion ;)
Maybe because it's bad in terms of complexity and it mutates the input.
how did i dont think of this. smh
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Very interesting. There are (at least) 3 ways to solve it and one of them can be implemented by two similar ideas.
Print the input of the tests your code fails, try your code here: https://pythontutor.com/visualize.html#mode=edit
Direct my attention to a problem in my code, please.
Yeah but some careless ppl like me will not notice that until try to solve it and get error. xd
Thanks anyway.
The function's name should be
declareWinner
notdeclare_winner
.Sorry... but in C++ the kata has to be redesigned, as is it is a sound example of BAD C translation to C++
I don't raise an issue but...
Codewars is a learning platform
a) use std::unique_ptr if you want to use pointers..
b) but could be better to use refs (Fighter &fighter1) in the call to 'declare_winner' . This would allow to use exactely the kind of prototype stated in the details:
instead of using naked pointers..
c) all pseudo "hidden" parms of Fighter class have setters and getters which is (generally) a bad practice in C++.
d) setHealth() ? should be transformed in "receiveDamage()" returning bool (true) if the fighter is still alive.
This comment is hidden because it contains spoiler information about the solution
sorry if this question is dumb but ive been trying to search for what the 'this.variable' in the object does/ means. in this case its this.name, this.health ect.. but im having a hard time finding an answer i understand well. can anyone explain it at all?