Langage C++. Fonction qui retourne un vecteur

Fermé
haloremi Messages postés 304 Date d'inscription lundi 10 mars 2008 Statut Membre Dernière intervention 6 novembre 2015 - 21 janv. 2012 à 11:12
KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 - 21 janv. 2012 à 14:18
Bonjour,
j'ai un léger problème je n'arrive pas à retourner un vecteur avec un fonction. Je m'explique :
j'ai une class toto.h:
#ifndef TOTO_H
#define TOTO_H
#include <string>
#include <vector>
#include <iostream>
using namespace std;

class toto
{
private:
vector<string> variable;//creer un tableau de string Vide
public:
toto();
toto(string nom);
vector<string>& getEntreevariable();
};
#endif

et une autre class titi.h ou je déclare un type "toto _toto;" pour pouvoir utiliser ma fonction get. Donc dans mon titi.c je fait par ex: string text = _toto.getvariable[0]; et la il me met une erreur à la compilation :

error C3867: &'toto::getvariable' : liste d'arguments manquante dans l'appel de fonction ; utilisez 'toto::getvariable' pour créer un pointeur vers membre

error C2109: un indice requiert un type tableau ou pointeur.

Merci de votre aide.


A voir également:

1 réponse

KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
21 janv. 2012 à 14:18
En gros le compilateur te demande ce qu'est getvariable et en particulier getvariable[0]
En effet tu pourrais faire _toto.variable (attention : private !) ou _toto.getEntreeVariable(), mais _toto.getvariable[0] n'a pas de sens car getvariable n'existe pas !
0