Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 11-03-2009, 12:21 AM   PM User | #1
shlagish
Senior Coder

 
Join Date: Apr 2003
Location: Canada
Posts: 1,050
Thanks: 2
Thanked 0 Times in 0 Posts
shlagish is an unknown quantity at this point
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;
	}
	
}
Jeu is a class which has a private member joueurs_ which is a vector of pointers to objects of class Joueur. It is declared like this:
Code:
		vector<Joueur*> joueurs_;
The public method lancer() is supposed to call, for every Joueur in vector joueurs_, it's own public method jouer().
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
This is translated from spanish so the words might not be exact.,,

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
shlagish is offline   Reply With Quote
Old 11-03-2009, 12:33 AM   PM User | #2
oracleguy
The Spaminator


 
Join Date: Jun 2002
Location: USA
Posts: 7,287
Thanks: 1
Thanked 148 Times in 145 Posts
oracleguy has a spectacular aura aboutoracleguy has a spectacular aura about
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
oracleguy is offline   Reply With Quote
Old 11-03-2009, 08:41 PM   PM User | #3
shlagish
Senior Coder

 
Join Date: Apr 2003
Location: Canada
Posts: 1,050
Thanks: 2
Thanked 0 Times in 0 Posts
shlagish is an unknown quantity at this point
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
shlagish is offline   Reply With Quote
Old 11-04-2009, 12:04 AM   PM User | #4
oracleguy
The Spaminator


 
Join Date: Jun 2002
Location: USA
Posts: 7,287
Thanks: 1
Thanked 148 Times in 145 Posts
oracleguy has a spectacular aura aboutoracleguy has a spectacular aura about
Quote:
Originally Posted by shlagish View Post
Are expression always evaluated from right to left like this? (apart from arithmetic expressions of course)
No but there is operator order, see: http://www.cppreference.com/wiki/operator_precedence
__________________
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
oracleguy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:37 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.