IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

pointeur de référence en param de fonction


Sujet :

C++

  1. #1
    Membre confirmé
    Inscrit en
    Novembre 2002
    Messages
    55
    Détails du profil
    Informations forums :
    Inscription : Novembre 2002
    Messages : 55
    Par défaut pointeur de référence en param de fonction
    Bonjour,
    j'ai un code, je ne sais pas trop comment m'y prendre. J'ai une classe CArrayString codée ci-dessous. Mon problème sur le passage en paramètre de fonctions. Je ne récupère pas ce que j'écris dans la fonction. Je ne vois pas comment la réécrire? Merci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    class CArrayString  
    {
     
    public:
     
    	CArrayString(int nb_col);
    	virtual ~CArrayString();
     
    	void	SetValue(int line, int column, CString value);
    	CString	GetValue(int line, int column);
    	int		GetLines();
    	int		GetCols();
     
     
    protected:
     
    	int								ci_nb_cols;
    	CArray<CString, CString&>	*	ca_array;
     
     
    };
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
     
    CArrayString::CArrayString(int nb_col)
    {
    	ci_nb_cols	= nb_col;
    	ca_array	= new CArray<CString, CString&>[ci_nb_cols];
     
    }
     
     
    CArrayString::~CArrayString()
    {
    	for(int i=0; i<ci_nb_cols; ++i)
    		ca_array[i].RemoveAll();
     
    /*	if ( ca_array )
    		delete ca_array;*/
     
    }
     
     
    int CArrayString::GetLines()
    {
    	if ( ca_array )
    		return ca_array[0].GetSize();
     
    	return 0;
     
    }
     
     
    int	CArrayString::GetCols()
    {
    	if ( ca_array )
    		return ci_nb_cols;
     
    	return 0;
     
    }
     
     
    void CArrayString::SetValue(int line, int column, CString value)
    {
    	if ( ca_array && line >= 0 && column >= 0 && column < ci_nb_cols )
    		ca_array[column].SetAtGrow(line, value);
     
    }
     
     
    CString	CArrayString::GetValue(int line, int column)
    {
    	if (ca_array && ca_array->GetSize() > column && line >= 0 && column >= 0 && line < ca_array[0].GetSize() && column < ci_nb_cols )
    		return ca_array[column].GetAt(line);
     
    	return "";
     
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
     
    LoadList(CString psRequest, CArrayString *&psList, CArrayString *&psColumnNameList, CString &psErrmsg)
    {	
    	...
     
    	psList = NULL;
     
    	int nb_lines = (int)ptrMyOleDB->GetRecordCount();
     
    	if ( nb_lines <= 0 )
    		return true;
     
    	int nb_cols = (int)ptrMyOleDB->GetFieldCount();
     
    	if ( nb_cols <= 0 )
    		return true;
     
    	int		col;
    	CString buffer;
    	psList = new CArrayString(nb_cols);
     
    	for( int i=0; i<nb_lines; ++i )
    	{
    		for(col=0; col<nb_cols; ++col)
    		{
    			ptrMyOleDB->GetFieldValue(col, buffer);
    			psList->SetValue(i, col, buffer);
    		}
    	}
     
            // Verif
    	for(int i=0; i<psList->GetLines(); i++)
    	{
    		for(int j=0; j<psList->GetCols(); j++)
    		{
    			CString temp = psList->GetValue(i, j); // ok, je récupère toutes les valeurs
    		}
    	}
     
    	return true;
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    CArrayString *psList = NULL;
    LoadList(psRequest, psList, psColumnNameList, psErrmsg);       
    // Verif
     
     
    	for(int i=0; i<list->GetLines(); i++)
    	{
    		for(int j=0; j<list->GetCols(); j++)
    		{
    			CString temp = list->GetValue(i, j); // Je récupère la première valeur mais pas les suivantes!!!!!
    		}
    	}

  2. #2
    Membre confirmé
    Inscrit en
    Novembre 2002
    Messages
    55
    Détails du profil
    Informations forums :
    Inscription : Novembre 2002
    Messages : 55
    Par défaut
    J'ai fait qques erreurs à la réecriture de code.
    Merci de votre aide

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    class CArrayString  
    {
     
    public:
     
    	CArrayString(int nb_col);
    	virtual ~CArrayString();
     
    	void	SetValue(int line, int column, CString value);
    	CString	GetValue(int line, int column);
    	int		GetLines();
    	int		GetCols();
     
     
    protected:
     
    	int								ci_nb_cols;
    	CArray<CString, CString&>	*	ca_array;
     
     
    };
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
     
    CArrayString::CArrayString(int nb_col)
    {
    	ci_nb_cols	= nb_col;
    	ca_array	= new CArray<CString, CString&>[ci_nb_cols];
     
    }
     
     
    CArrayString::~CArrayString()
    {
    	for(int i=0; i<ci_nb_cols; ++i)
    		ca_array[i].RemoveAll();
     
    /*	if ( ca_array )
    		delete ca_array;*/
     
    }
     
     
    int CArrayString::GetLines()
    {
    	if ( ca_array )
    		return ca_array[0].GetSize();
     
    	return 0;
     
    }
     
     
    int	CArrayString::GetCols()
    {
    	if ( ca_array )
    		return ci_nb_cols;
     
    	return 0;
     
    }
     
     
    void CArrayString::SetValue(int line, int column, CString value)
    {
    	if ( ca_array && line >= 0 && column >= 0 && column < ci_nb_cols )
    		ca_array[column].SetAtGrow(line, value);
     
    }
     
     
    CString	CArrayString::GetValue(int line, int column)
    {
    	if (ca_array && ca_array->GetSize() > column && line >= 0 && column >= 0 && line < ca_array[0].GetSize() && column < ci_nb_cols )
    		return ca_array[column].GetAt(line);
     
    	return "";
     
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
     
    LoadList(CString psRequest, CArrayString *&psList, CArrayString *&psColumnNameList, CString &psErrmsg)
    {	
    	...
     
    	psList = NULL;
     
    	int nb_lines = (int)ptrMyOleDB->GetRecordCount();
     
    	if ( nb_lines <= 0 )
    		return true;
     
    	int nb_cols = (int)ptrMyOleDB->GetFieldCount();
     
    	if ( nb_cols <= 0 )
    		return true;
     
    	int		col;
    	CString buffer;
    	psList = new CArrayString(nb_cols);
     
    	for( int i=0; i<nb_lines; ++i )
    	{
    		for(col=0; col<nb_cols; ++col)
    		{
    			ptrMyOleDB->GetFieldValue(col, buffer);
    			psList->SetValue(i, col, buffer);
    		}
    	}
     
            // Verif
    	for(int i=0; i<psList->GetLines(); i++)
    	{
    		for(int j=0; j<psList->GetCols(); j++)
    		{
                            // ok, je récupère toutes les valeurs
    			CString temp = psList->GetValue(i, j); 
    		}
    	}
     
    	return true;
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
         CArrayString *List = NULL;
         LoadList(psRequest, List, psColumnNameList, psErrmsg);       
         // Verif
         for(int i=0; i<List->GetLines(); i++)
    	{
    		for(int j=0; j<List->GetCols(); j++)
    		{
                            // Je récupère la première valeur mais pas les suivantes!!!!!
    			CString temp = List->GetValue(i, j); 
    		}
    	}

  3. #3
    Rédacteur
    Avatar de 3DArchi
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    7 634
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 7 634
    Par défaut
    Salut,
    Le but n'est quand même pas de réécrire la MFC CStringArray ?
    Il s'agit d'un exercice de cours ? Sinon std::vector<std::string> convient assez bien à un tableau de chaînes de caractères.

Discussions similaires

  1. Pointeur sur référence ?
    Par koala01 dans le forum C++
    Réponses: 24
    Dernier message: 15/01/2008, 17h54
  2. Pointeur vers une table dans une fonction
    Par Chatbour dans le forum Oracle
    Réponses: 2
    Dernier message: 03/05/2007, 12h28
  3. pointeur ou référence
    Par damien77 dans le forum C++
    Réponses: 2
    Dernier message: 23/03/2007, 16h43
  4. pointeurs constants et prototype de ma fonction
    Par salseropom dans le forum C
    Réponses: 3
    Dernier message: 23/05/2006, 18h03
  5. Référence en retour de fonction, à transformer en hash
    Par raoulchatigre dans le forum Langage
    Réponses: 4
    Dernier message: 15/07/2005, 14h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo