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

MFC Discussion :

[MFC] Tableau 2 dimensions [Fait]


Sujet :

MFC

  1. #1
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    46
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2006
    Messages : 46
    Par défaut [MFC] Tableau 2 dimensions
    Bonjour, je travaille actuellement avec Microsoft Embedded Visual C++ 4.0 et j'essaye de créer un tableau à deux dimensions.

    En gros j'essaye de faire qq chose dans le genre:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    CArray<CArray<CString,CString>,CArray<CString,CString>> tableau;
    Bien sur ca ne marche pas, mais j'aimerai savoir comment il faut s'y prendre pour faire un tableau à deux dimensions sachant que comme je bosse en MFC le type CArray me semble plus approprié ????

    Merci bcp d'avance

  2. #2
    Rédacteur
    Avatar de bigboomshakala
    Homme Profil pro
    Consultant Web .NET
    Inscrit en
    Avril 2004
    Messages
    2 077
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Consultant Web .NET
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2004
    Messages : 2 077
    Par défaut
    salut, essaie

    CArray< CArray<CString,CString&> , CArray<CString,CString&>* >

  3. #3
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 393
    Par défaut
    1. Qu'est-ce qui foire exactement ?
    2. Tu es sûr que ce n'est pas juste un oubli d'espace dans le >> ?
    3. Généralement, on utilise des références pour le second paramètre d'une classe de collection MFC...
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  4. #4
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par défaut
    salut,
    bon decidement :
    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
     
    #ifndef __ARRAYEX_H__
    #define __ARRAYEX_H__
     
    #if _MSC_VER < 0x0600
        #pragma warning(disable : 4786) //identifier was truncated to '255' characters in the debug information
    #endif
     
    #ifndef __AFXTEMPL_H__
        #include <afxtempl.h>
    #endif
     
    template<class TYPE, class ARG_TYPE>
    class CArrayEx: public CArray<TYPE, ARG_TYPE>
    {
        public:
     
        CArrayEx();
        CArrayEx(const CArrayEx &x);
     
        // assigment operator
        CArrayEx &operator = (const CArrayEx& x);
     
    };
     
    template<class TYPE, class ARG_TYPE>
    inline CArrayEx<TYPE, ARG_TYPE>::CArrayEx():CArray<TYPE, ARG_TYPE>()
    {
    }
     
     
    template<class TYPE, class ARG_TYPE>
    inline CArrayEx<TYPE, ARG_TYPE>::CArrayEx(const CArrayEx &x)
    {
        *this = x;
    }
     
    template<class TYPE, class ARG_TYPE>
    inline CArrayEx<TYPE, ARG_TYPE> &
           CArrayEx<TYPE, ARG_TYPE>::operator = (const CArrayEx& x)
    {
        if(this!=&x)
        {
            RemoveAll();
            Copy(x);
        }
        return *this;
    }
    #endif
    exemple:
    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
     
    typedef CArrayEx<CString ,const char *> StringArray; // Like CStringArray !!
        CArrayEx<StringArray,StringArray &> ArOfstrArray;    
     
        StringArray strArray;
        strArray.Add("coucou");
     
        ArOfstrArray.Add(strArray);
        for(i=0;i<ArOfstrArray.GetSize();i++)
        {
            for(int n=0;n<ArOfstrArray[i].GetSize();n++)
            {
                TRACE("\n Array[%d][%d]=%s",i,n,static_cast<const char *>(ArOfstrArray[i].GetAt(n)));
            }
        }
    meme remarque que dans un autre post ,le CArray n'a pas d'operateur et de constructeur de copie....


  5. #5
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    46
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2006
    Messages : 46
    Par défaut
    Ok ca marche niquel ...

    Merci bcp pour vos conseils.

    Franchement rien à dire vous êtes vraiment des stars !!!!!!!


    Merci encore.

  6. #6
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    46
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2006
    Messages : 46
    Par défaut
    Bon ok je reviens à la charge même si ca marche niquel.

    J'aimerai pouvoir utiliser le tableau nouvellement créé dans toute ma classe, cependant quand je veux mettre le code suivant dans le .h :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    typedef CArrayEx<CString ,CString> element; 
    CArrayEx<element,element &> tableau; 
    element elemtab;
    Ca me met un paquet d'erreur... Il aime vraiment pas ça ...

    Est-ce que c'est normal, j'ai pas le droit d'affecter mon tableau en variable globale de ma classe ????

  7. #7
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par défaut
    je vois pas le pb:
    exemple dans un .h pour une dialogue:
    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
     
    // TestDlgDlg.h : header file
    //
     
    #if !defined(AFX_TESTDLGDLG_H__01B6C0C9_6C32_4A10_96D7_39DB7DA8BCA5__INCLUDED_)
    #define AFX_TESTDLGDLG_H__01B6C0C9_6C32_4A10_96D7_39DB7DA8BCA5__INCLUDED_
     
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    /////////////////////////////////////////////////////////////////////////////
    // CTestDlgDlg dialog
     
    #include "Arrayex.h" // la definition du CArrayEx
     
    typedef CArrayEx<CString ,const char *> StringArray; // ou CStringArray !!
    class CTestDlgDlg : public CDialog
    {
    // Construction
    public:
        CTestDlgDlg(CWnd* pParent = NULL);    // standard constructor
     
    // Dialog Data
        //{{AFX_DATA(CTestDlgDlg)
        //}}AFX_DATA
     
        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CTestDlgDlg)
        protected:
        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
        virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
        //}}AFX_VIRTUAL
     
        CArrayEx<StringArray,StringArray &> m_ArOfstrArray;    
    //......
    };

  8. #8
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    46
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2006
    Messages : 46
    Par défaut
    Ben le problème est la regarde le .h :


    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
    57
    58
    59
    // pathoDlg.h : header file
    //
     
    #if !defined(AFX_PATHODLG_H__A0C11733_6AB4_4007_9291_E1B320FB7934__INCLUDED_)
    #define AFX_PATHODLG_H__A0C11733_6AB4_4007_9291_E1B320FB7934__INCLUDED_
     
    #if _MSC_VER >= 1000
    #pragma once
    #endif // _MSC_VER >= 1000
     
    /////////////////////////////////////////////////////////////////////////////
    // CPathoDlg dialog
     
    class CPathoDlg : public CDialog
    {
    // Construction
    public:
     
    	void BSTRtoASC(BSTR str, char *&strRet);
    	bool InitCtrlBox();
    	CPathoDlg(CWnd* pParent = NULL);	// standard constructor
     
     
    // Dialog Data
    	//{{AFX_DATA(CPathoDlg)
    	enum { IDD = IDD_PATHO_DIALOG };
    	CListCtrl	m_clistctrl;
    	//}}AFX_DATA
     
    	// ClassWizard generated virtual function overrides
    	//{{AFX_VIRTUAL(CPathoDlg)
    	protected:
    	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
    	//}}AFX_VIRTUAL
     
    	CString File;
    	int nSelected;
     
    	CArray<CString,CString> entete;
    	typedef CArrayEx<CString ,CString> element; // Like CStringArray !!
            CArrayEx<element,element &> tableau; 
    	element elemtab;
     
    // Implementation
    protected:
    	HICON m_hIcon;
     
    	// Generated message map functions
    	//{{AFX_MSG(CPathoDlg)
    	virtual BOOL OnInitDialog();
    	afx_msg void OnEnregist();
    	//}}AFX_MSG
    	DECLARE_MESSAGE_MAP()
    };
     
    //{{AFX_INSERT_LOCATION}}
    // Microsoft eMbedded Visual C++ will insert additional declarations immediately before the previous line.
     
    #endif // !defined(AFX_PATHODLG_H__A0C11733_6AB4_4007_9291_E1B320FB7934__INCLUDED_)

    Et mon compilateur qui est pas content :

    r:\baptiste\projet\patho\pathodlg.h(39) : error C2143: syntax error : missing ';' before '<'
    r:\baptiste\projet\patho\pathodlg.h(39) : error C2501: 'CArray' : missing storage-class or type specifiers
    r:\baptiste\projet\patho\pathodlg.h(39) : error C2059: syntax error : '<'
    r:\baptiste\projet\patho\pathodlg.h(39) : error C2238: unexpected token(s) preceding ';'
    r:\baptiste\projet\patho\pathodlg.h(40) : error C2143: syntax error : missing ';' before '<'
    r:\baptiste\projet\patho\pathodlg.h(40) : error C2059: syntax error : '<'
    r:\baptiste\projet\patho\pathodlg.h(40) : error C2238: unexpected token(s) preceding ';'
    r:\baptiste\projet\patho\pathodlg.h(41) : error C2059: syntax error : '<'
    r:\baptiste\projet\patho\pathodlg.h(41) : error C2238: unexpected token(s) preceding ';'
    r:\baptiste\projet\patho\pathodlg.h(42) : error C2146: syntax error : missing ';' before identifier 'elemtab'
    r:\baptiste\projet\patho\pathodlg.h(42) : error C2501: 'element' : missing storage-class or type specifiers
    r:\baptiste\projet\patho\pathodlg.h(42) : error C2501: 'elemtab' : missing storage-class or type specifiers
    pathoDlg.cpp
    r:\baptiste\projet\patho\pathodlg.h(39) : error C2143: syntax error : missing ';' before '<'
    r:\baptiste\projet\patho\pathodlg.h(39) : error C2501: 'CArray' : missing storage-class or type specifiers
    r:\baptiste\projet\patho\pathodlg.h(39) : error C2059: syntax error : '<'
    r:\baptiste\projet\patho\pathodlg.h(39) : error C2238: unexpected token(s) preceding ';'
    r:\baptiste\projet\patho\pathodlg.h(40) : error C2143: syntax error : missing ';' before '<'
    r:\baptiste\projet\patho\pathodlg.h(40) : error C2059: syntax error : '<'
    r:\baptiste\projet\patho\pathodlg.h(40) : error C2238: unexpected token(s) preceding ';'
    r:\baptiste\projet\patho\pathodlg.h(41) : error C2059: syntax error : '<'
    r:\baptiste\projet\patho\pathodlg.h(41) : error C2238: unexpected token(s) preceding ';'
    r:\baptiste\projet\patho\pathodlg.h(42) : error C2146: syntax error : missing ';' before identifier 'elemtab'
    r:\baptiste\projet\patho\pathodlg.h(42) : error C2501: 'element' : missing storage-class or type specifiers
    r:\baptiste\projet\patho\pathodlg.h(42) : error C2501: 'elemtab' : missing storage-class or type specifiers
    R:\Baptiste\projet\patho\pathoDlg.cpp(142) : fatal error C1903: unable to recover from previous error(s); stopping compilation
    Je précise que la ligne ou commence les erreurs c'est bien

    CArray<CString,CString> entete;

    et que les deux déclarations avant marche niquel.

    PS: je suis sous Embedded Visual C++ 4.0 (ca peut venir de la ???)

  9. #9
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par défaut
    regarde bien mon post !,
    le typedef n'est pas dans la classe ....

  10. #10
    Membre averti
    Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    46
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2006
    Messages : 46
    Par défaut
    J'ai rien dis ...

    Pas ajouté les librairies au .h !!!!


    Je --> [].

    Dsl du dérangement et merci bcp encore.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [tableau à 2 dimensions] association String et float
    Par LoLoSS dans le forum Collection et Stream
    Réponses: 3
    Dernier message: 12/07/2004, 10h53
  2. Tableau à n dimensions
    Par youb dans le forum MFC
    Réponses: 10
    Dernier message: 13/05/2004, 14h13
  3. [MFC] Mise à jour dimension des CDialogBar
    Par Kevgeii dans le forum MFC
    Réponses: 2
    Dernier message: 14/01/2004, 22h47
  4. Passage d'un tableau à deux dimensions
    Par karl3i dans le forum C
    Réponses: 3
    Dernier message: 20/10/2003, 14h50
  5. Réponses: 23
    Dernier message: 21/08/2003, 07h16

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