0

I am trying to make a turn-based fighting game and there is a character class and a move class.

The error occurs when I was developing the character class part, in which there is a function TakeTurn(character oppoCharacter, cmove chosenMove, field currentField). It's meaning is letting the character object to cast a move against the opponent character. This function is composed with two other functions in the move class. First of them is spelling the move, and the other one is launching the move.

I tried everything I can and it still doesn't work. I guess the problem is related to the "this" pointer, but I am not sure.

In the character.cpp file:

void character::TakeTurn(character oppoCharacter, cmove chosenMove,field currentField){
    chosenMove.SpellMove(this*, oppoCharacter, currentField.FStatusL);
    chosenMove.LaunchMove(this*, oppoCharacter, currentField.FStatusL);
}

In the character.h file:

void TakeTurn(character oppoCharacter, cmove chosenMove,field currentField);

The error message:

[ 10%] Building CXX object CMakeFiles/gods.dir/character.cpp.o
/Users/otbooster/Downloads/2019up/cpp/gods/character.cpp:35:31: error: expected expression
        chosenMove.SpellMove(this*, oppoCharacter, currentField.FStatusL);
                              ^
    /Users/otbooster/Downloads/2019up/cpp/gods/character.cpp:36:32: error: expected expression
            chosenMove.LaunchMove(this*, oppoCharacter, currentField.FStatusL);
                                   ^
        2 errors generated.
        make[3]: *** [CMakeFiles/gods.dir/character.cpp.o] Error 1
        make[2]: *** [CMakeFiles/gods.dir/all] Error 2
        make[1]: *** [CMakeFiles/gods.dir/rule] Error 2
        make: *** [gods] Error 2
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Irrawa
  • 23
  • 5
  • 1
    Typo: `this*` --> `*this` ? – G.M. May 16 '19 at 09:33
  • `this*`? Did you mean `*this`? – Wander3r May 16 '19 at 09:34
  • 1
    I suggest you take a couple of steps back, go back you your books, tutorials or class-notes (or [get a few good books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282) to read) and reread the part about pointers and how to use them. – Some programmer dude May 16 '19 at 09:34
  • 1
    As an aside, it's very likely you're gonna want `TakeTurn(character&, ...)` so you pass your character as a reference to the original, not a copy. – Tas May 16 '19 at 09:34
  • Thank you and problem solved. I just finished my pointer lesson in cpp and and still not quite well in handling it. It is the typo problem and *this is right. – Irrawa May 16 '19 at 10:29

1 Answers1

0

I think you would like to get reference of this, in this case please use:

chosenMove.LaunchMove(*this...
Dewfy
  • 23,277
  • 13
  • 73
  • 121