C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[syntaxe] pointeur sur vecteur

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Adrien
Guest





PostPosted: Mon Oct 17, 2005 4:11 pm    Post subject: [syntaxe] pointeur sur vecteur Reply with quote



Bonjour,

J'ai un petit souci au niveau de la syntaxe pour accéder à une donnée
d'un type struct:

Je m'explique:
Soit la structure

struct Point
{
public:
std::vector <std::string> * names ;
}

et j'aimerais accéder depuis une autre fonction (main() on va dire) au 6e
element de names.

j'ai essayé:
Point point;
....
std::string toto = point.(*names)[6] ;

et j'obtiens un error: `names' undeclared (first use this function)
(avec gcc 3.3.5)

Il y a-t-il une façon d'accéder à (*names)[6] en une ligne de code ?

Merci d'avance.
Adrien
Back to top
Jean-Marc Bourguet
Guest





PostPosted: Mon Oct 17, 2005 4:14 pm    Post subject: Re: [syntaxe] pointeur sur vecteur Reply with quote



Adrien <adrien-news (AT) wizzi (DOT) net> writes:

Quote:
j'ai essayé:
Point point;
...
std::string toto = point.(*names)[6] ;

Il y a-t-il une façon d'accéder à (*names)[6] en une ligne de code ?

std::string toto = (*point.names)[6];

A+

--
Jean-Marc
FAQ de fclc++: http://www.cmla.ens-cachan.fr/~dosreis/C++/FAQ
C++ FAQ Lite en VF: http://www.ifrance.com/jlecomte/c++/c++-faq-lite/index.html
Site de usenet-fr: http://www.usenet-fr.news.eu.org

Back to top
Adrien
Guest





PostPosted: Tue Oct 18, 2005 7:49 am    Post subject: Re: [syntaxe] pointeur sur vecteur Reply with quote



Jean-Marc Bourguet wrote:

Quote:
std::string toto = (*point.names)[6];

A+


Merci !

Back to top
kanze
Guest





PostPosted: Wed Oct 19, 2005 6:47 am    Post subject: Re: pointeur sur vecteur Reply with quote

Jean-Marc Bourguet wrote:
Quote:
Adrien <adrien-news (AT) wizzi (DOT) net> writes:

j'ai essayé:
Point point;
...
std::string toto = point.(*names)[6] ;

Il y a-t-il une façon d'accéder à (*names)[6] en une ligne de code ?

std::string toto = (*point.names)[6];

Ceci dit, je me poserais bien la question : pourquoi un pointeur
à vector, et non un vector tout court. (À part dans les objets
fonctionnels pour la STL, je ne vois pas trop d'intérêt.)

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.