![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #1 |
|
Senior Coder ![]() Join Date: Apr 2003
Location: Canada
Posts: 1,050
Thanks: 2
Thanked 0 Times in 0 Posts
![]() |
can't fetch vector -> pointer -> object -> method using *iterator->method(); (C++)
This is part of a code I'm writing as a school assignment. The problem has nothing to do with the homework topic (semaphores).
Here is what I have: Code:
void Jeu::lancer()
{
vector<Joueur*>::iterator joueur = joueurs_.begin();
while(joueur != joueurs_.end())
{
*joueur->jouer(); // This is the tricky bit
++joueur;
}
}
Code:
vector<Joueur*> joueurs_; This is the compilation error I get, which I don't quite understand.. Code:
jeu.cpp:20: error: request for member ‘jouer’ in ‘* joueur.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = Joueur**, _Container = std::vector<Joueur*, std::allocator<Joueur*> >]()’, which is of type ‘Joueur*’ which is not a class I think I might not be fetching the object correctly, but I tried many different ways, and none of the following work: *joueur->jouer(); **joueur->jouer(); ***joueur.jouer(); Does anybody understand what I'm doing wrong here? Thanks a bunch in advance
__________________
Shawn |
|
|
|
|
|
PM User | #2 |
|
The Spaminator ![]() ![]() Join Date: Jun 2002
Location: USA
Posts: 7,287
Thanks: 1
Thanked 148 Times in 145 Posts
![]() ![]() |
You are missing parenthesis.
Code:
(*joueur)->jouer();
__________________
OracleGuy My Blog "... the VP of our third biggest account started sweating bullets in our latest project status conference when Roy stood up and asserted: 'We don’t code our products for SMACKTARDS.'" - Daily Victim #564 |
|
|
|
|
|
PM User | #3 |
|
Senior Coder ![]() Join Date: Apr 2003
Location: Canada
Posts: 1,050
Thanks: 2
Thanked 0 Times in 0 Posts
![]() |
and... it works
Well thank you very much, it does work.
I guess the problem was it was trying to do the -> before the *... Thus trying to access the method of that which is pointed to by the iterator, and seeing what the return value points to. Are expression always evaluated from right to left like this? (apart from arithmetic expressions of course)
__________________
Shawn |
|
|
|
|
|
PM User | #4 | |
|
The Spaminator ![]() ![]() Join Date: Jun 2002
Location: USA
Posts: 7,287
Thanks: 1
Thanked 148 Times in 145 Posts
![]() ![]() |
Quote:
__________________
OracleGuy My Blog "... the VP of our third biggest account started sweating bullets in our latest project status conference when Roy stood up and asserted: 'We don’t code our products for SMACKTARDS.'" - Daily Victim #564 |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Rate This Thread | |
|
|