| koga (3) | |
|
Im working with some frame work for a university project and : player1->passCardToPile(*pile, 1, true); //this works it passes a card from player1's hand to the pile which is just a pile of cards. but player1.passCardToPile(*pile, 1, true); doesn't work , is it because player1 is a pointer. also passcardtopile is in a class type. Just a quick question thanks! :) | |
|
|
|
| L B (3816) | |
|
. is for actual objects themselves and references. -> is for pointers and objects that act like pointers. | |
|
|
|
| koga (3) | |
| okay thanks :) | |
|
|
|
| L B (3816) | |||
I forgot to mention, these two lines are the same:
| |||
|
|
|||
| Bandar (45) | |
|
If you would like to access a function in a class and you created a pointer object then you use ->. every function in a class has at least implicit parameter which is ->. This is to let the compiler distinguish between the functions of the objects. | |
|
|
|
| Bandar (45) | |||
|
a->b; (*a).b; They are same. The first one makes perfect sense in terms of naming because it suggets its purpose. In other words, it points to the objet..
As you see there are two ways to access to printValue() function. If you didn't get it let me know to elaborate. | |||
|
Last edited on
|
|||