Hi there, complete novice C++ programmer here, Having a bit of a problem using pointers to class methods inside functions. I think I said that right?
Basically I was having a problem were I would create an instance of a class I made called "pokemon", inside the main function. Then in another function called setup() I would use methods (SetName()) from the pokemon class to change members (variables) of the class pokemon, but once the setup() function returned the members of the class were destroyed/empty? So I was think something to do with scope so I tried using pointers and that like below but I not sure if I am doing it right.
The code below is just a snippet from a very larger function. Basically I get this error below.
So I try *player->SetName(name); but it gave me this error
Any ideas?
Basically I was having a problem were I would create an instance of a class I made called "pokemon", inside the main function. Then in another function called setup() I would use methods (SetName()) from the pokemon class to change members (variables) of the class pokemon, but once the setup() function returned the members of the class were destroyed/empty? So I was think something to do with scope so I tried using pointers and that like below but I not sure if I am doing it right.
The code below is just a snippet from a very larger function. Basically I get this error below.
| Quote: |
| : error C2228: left of '.SetName' must have class/struct/union
type is 'pokemon *' did you intend to use '->' instead? |
| Code: |
|
int setup(pokemon * player1){ *player1.SetName(name); // error is located on this line return 1; }; |
So I try *player->SetName(name); but it gave me this error
| Quote: |
| error C2100: illegal indirection |
Any ideas?
