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 :

probleme avec classe erreur C1004


Sujet :

C++

  1. #1
    Nouveau Candidat au Club
    Inscrit en
    Juin 2010
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Juin 2010
    Messages : 2
    Points : 1
    Points
    1
    Par défaut probleme avec classe erreur C1004
    Bonjour,

    J'ai un petit soucis avec la définition d'une classe voici mon code

    MonSystem.cpp

    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
    #include <iostream>
    #include "MonSystem.h"
    #include "DynamicalSystem.h"
     
     
     
    MonSystem::MonSystem() : DynamicalSystem(4)
    {
        //appel le constructeur DynamicalSystem(4 variables)
        //constructor
    }
     
    MonSystem::~MonSystem()
    {
        //destructor
    }
     
    void MonSystem::EDP(double t, double *X, double *dX)
    {
        //Crée ici le system d'equation différentiel à résoudre
     
    }
     
    void MonSystem::Integrator()
    {
        double y, t1, t2;
        DynamicalSystem::RungeKutta(*y,t1,t2);
        //Utilise runge kutta
    }
     
    // ICI : erreur C1004: fin de fichier inattendue rencontrée

    Et la MonSystem.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
    #ifndef MONSYSTEM_H
    #define MONSYSTEM_H
     
    #include "DynamicalSystem.h"
     
    class DynamicalSystem;
     
    class MonSystem : public DynamicalSystem
    {
        public:
     
            MonSystem() : DynamicalSystem(4)
            virtual ~MonSystem()
            void EDP (double t, double *X, double *dX)
            void Integrator()
     
        protected:
     
        private:
     
    }
     
    #endif // MONSYSTEM_H
    Quand je compile j'ai une erreur C1004 : fin de fichier inattendue à la ligne 32 de MonSystem.cpp

    Je ne comprend pas d'où viens cette erreur. Puis-je avoir un peu d'aide ?

    Merci d'avance

    JéjéJames

  2. #2
    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
    Points : 13 017
    Points
    13 017
    Par défaut
    Salut,
    manque un ';' à la fin de la déclaration de ta classe MonSystem dans le .h.
    La déclaration anticipée de DynamicalSystem dans MonSystem.h est inutile car 1/ le fichier #include "DynamicalSystem.h" est inclus juste au dessus et 2/ on ne peut pas utiliser une définition incomplète (la déclaration anticipée) pour un héritage.
    Par hasard, DynamicalSystem.h ne fait pas d'include de MonSystem.h ???

  3. #3
    Nouveau Candidat au Club
    Inscrit en
    Juin 2010
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Juin 2010
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Bonjour,

    J'ai essayer de rajouter un ';' a la fin de mon .h, j'obtiens alors l'erreur suivante :
    ERREUR C2969 : ';' la définition d'une onction membre doit ce terminer par {}

    A tout hasard je vous met la classe dynamical System :

    le point 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
    #ifndef DYNAMICALSYSTEM_H_INCLUDED
    #define DYNAMICALSYSTEM_H_INCLUDED
     
    //#include "MonSystem.h"
     
     // DYNAMICALSYSTEM_H_INCLUDED
     
     
     
    class DynamicalSystem
    {
        protected:
     
            int NVariable;
            double Precision;
            double Hestimate;
            double Hmin;
        public:
            DynamicalSystem(int n);
            virtual void EDP(double t,double *X,double *dX){};
            void RungeKutta(double *y, double t1,double t2);
            void SetPrecision(double p){Precision=p;};
            void SetHmin(double h){Hmin=h;};
            void SetHestimate(double h){Hestimate=h;};
     
        private:
            double *vector(int N);
            void nrerror(char * error_text);
            void free_vector(double *v);
            int odeint(double *ystart, double x1, double x2, double eps,
                        double h1, double hmin, int *nok, int *nbad);
            void rk4(double *y, double *dydx, double x, double h, double *yout);
            void rkqc(double *y, double *dydx, double *x, double htry,
                        double eps, double *yscal, double *hdid, double *hnext);
    };
    #endif
    le point cpp

    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
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    #include <iostream>
    #include <math.h>
    #include "DynamicalSystem.h"
    #include "rk4.h"
     
    using namespace std;
     
    DynamicalSystem::DynamicalSystem(int n)
    {
    	NVariable=n;
    	Precision=1.e-4;
    	Hmin=0.;
    	Hestimate=1.e-1;
    	//
    	// private var
    	//
    }
    //==============================================================
    void DynamicalSystem::nrerror(char * error_text)
    {
            cerr<<"Numerical Recipes run-time error : "<<error_text<<"...now exiting to system...\n";
    }
    //===========================================================================
    double *DynamicalSystem::vector(int N)
    {
            double *v;
            v= new double [N];
            if (!v) nrerror("allocation failure in vector()");
     	return v;
    }
    //========================================
    void DynamicalSystem::free_vector(double *v)
    {
            if(v) delete v;
    }
     
    //===========================================================================
    void  DynamicalSystem::rk4(double *y, double *dydx, double x, double h, double *yout)
    {
            int i;
            double xh,hh,h6,*dym,*dyt,*yt;
            dym=vector(NVariable);
            dyt=vector(NVariable);
            yt=vector(NVariable);
            hh=h*0.5;
            h6=h/6.0;
            xh=x+hh;
            for (i=0;i<NVariable;i++) yt[i]=y[i]+hh*dydx[i];
            EDP(xh,yt,dyt);
            for (i=0;i<NVariable;i++) yt[i]=y[i]+hh*dyt[i];
            EDP(xh,yt,dym);
            for (i=0;i<NVariable;i++) {
                    yt[i]=y[i]+h*dym[i];
                    dym[i] += dyt[i];
            }
            EDP(x+h,yt,dyt);
            for (i=0;i<NVariable;i++)
                    yout[i]=y[i]+h6*(dydx[i]+dyt[i]+2.0*dym[i]);
            free_vector(yt);
            free_vector(dyt);
            free_vector(dym);
    }
     
     
    //===========================================================================
     
    #define PGROW -0.20
    #define PSHRNK -0.25
    #define FCOR 0.06666666         /* 1.0/15.0 */
    #define SAFETY 0.9
    #define ERRCON 6.0e-4
     
     
    void  DynamicalSystem::rkqc(double *y, double *dydx, double *x, double htry,
                    double eps, double *yscal, double *hdid, double *hnext)
    {
            int i;
            double xsav,hh,h,temp,errmax;
            double *dysav,*ysav,*ytemp;
     
     
            dysav=vector(NVariable);
            ysav=vector(NVariable);
            ytemp=vector(NVariable);
            xsav=(*x);
            for (i=0;i<NVariable;i++) {
                    ysav[i]=y[i];
                    dysav[i]=dydx[i];
            }
            h=htry;
            for (;;) {
                    hh=0.5*h;
                    rk4(ysav,dysav,xsav,hh,ytemp);
                    *x=xsav+hh;
                    EDP(*x,ytemp,dydx);
                    rk4(ytemp,dydx,*x,hh,y);
                    *x=xsav+h;
                    if (*x == xsav) nrerror("Step size too small in routine RKQC");
                    rk4(ysav,dysav,xsav,h,ytemp);
                    errmax=0.0;
                    for (i=0;i<NVariable;i++) {
                            ytemp[i]=y[i]-ytemp[i];
                            temp=fabs(ytemp[i]/yscal[i]);
                            if (errmax < temp) errmax=temp;
                    }
                    errmax /= eps;
                    if (errmax <= 1.0) {
                            *hdid=h;
                            *hnext=(errmax > ERRCON ?
                                    SAFETY*h*exp(PGROW*log(errmax)) : 4.0*h);
                            break;
                    }
                    h=SAFETY*h*exp(PSHRNK*log(errmax));
            }
            for (i=0;i<NVariable;i++) y[i] += ytemp[i]*FCOR;
            free_vector(ytemp);
            free_vector(dysav);
            free_vector(ysav);
    }
     
    #undef PGROW
    #undef PSHRNK
    #undef FCOR
    #undef SAFETY
    #undef ERRCON
     
     
    //===========================================================================
     
    #define MAXSTP 10000
    #define TINY 1.0e-30
     
     
     
    int  DynamicalSystem::odeint(double *ystart, double x1, double x2, double eps,
                    double h1, double hmin, int *nok, int *nbad)
    {
            int nstp,i;
            double xsav,x,hnext,hdid,h;
            double *yscal,*y,*dydx;
     
     
            yscal=vector(NVariable);
            y=vector(NVariable);
            dydx=vector(NVariable);
            x=x1;
            h=(x2 > x1) ? fabs(h1) : -fabs(h1);
            *nok = (*nbad) =  0;
            for (i=0;i<NVariable;i++) y[i]=ystart[i];
            for (nstp=1;nstp<=MAXSTP;nstp++) {
                    EDP(x,y,dydx);
                    for (i=0;i<NVariable;i++)
                            yscal[i]=fabs(y[i])+fabs(dydx[i]*h)+TINY;
     
                    if ((x+h-x2)*(x+h-x1) > 0.0) h=x2-x;
                    rkqc(y,dydx,&x,h,eps,yscal,&hdid,&hnext);
                    if (hdid == h) ++(*nok); else ++(*nbad);
                    if ((x-x2)*(x2-x1) >= 0.0) {
                            for (i=0;i<NVariable;i++) ystart[i]=y[i];
     
                            free_vector(dydx);
                            free_vector(y);
                            free_vector(yscal);
                            return 0;
                    }
                    if (fabs(hnext) <= hmin) nrerror("Step size too small in ODEINT");
                    h=hnext;
            }
            nrerror("Too many steps in routine ODEINT");
            return 1;
    }
     
    #undef MAXSTP
    #undef TINY
     
     
    //=================================================================
     
    void DynamicalSystem::RungeKutta(double *y, double t1,double t2)
    {
     int nok,nbad;
     odeint(y, t1, t2,Precision,Hestimate,Hmin,&nok,&nbad);
     
    }
    la fonction rk4 utilise par dynamicalSystem :

    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
    #ifndef RK4_H_INCLUDED
    #define RK4_H_INCLUDED
     
     
     
     
    void nrerror(char * error_text);
     
    double *vector(int N);
     
    void free_vector(double *v);
     
    void  rk4(double *y, double *dydx, int n, double x, double h, double *yout,
                    void (*derivs)(double,double *,double *));
     
    void  rkqc(double *y, double *dydx, int n, double *x, double htry,
                    double eps, double *yscal, double *hdid, double *hnext,
                    void (*derivs)(double,double *,double *));
     
    int  odeint(double *ystart, int nvar, double x1, double x2, double eps,
                    double h1, double hmin, int *nok, int *nbad,
                    void (*derivs)(double,double *,double *));
     
    void RungeKutta(double *y, int N,double t1,double t2,void (*derivs)(double,double *,double *));
     
     
    #endif // RK4_H_INCLUDED
    le cpp :

    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
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    #include <iostream>
    #include <math.h>
     
    using namespace std;
     
    //==============================================================
    void nrerror(char * error_text)
    {
     
            cerr<<"Numerical Recipes run-time error : "<<error_text<<"...now exiting to system...\n";
            // exit(1);
    }
    //===========================================================================
    double *vector(int N)
     
    {
            double *v;
            v= new double [N];
            if (!v) nrerror("allocation failure in vector()");
     	return v;
    }
    //========================================
    void free_vector(double *v)
    {
            delete [] v;
    }
    //===========================================================================
    void  rk4(double *y, double *dydx, int n, double x, double h, double *yout,
                    void (*derivs)(double,double *,double *))
    {
            int i;
            double xh,hh,h6,*dym,*dyt,*yt;
            dym=vector(n);
            dyt=vector(n);
            yt=vector(n);
            hh=h*0.5;
            h6=h/6.0;
            xh=x+hh;
            for (i=0;i<n;i++) yt[i]=y[i]+hh*dydx[i];
            (*derivs)(xh,yt,dyt);
            for (i=0;i<n;i++) yt[i]=y[i]+hh*dyt[i];
            (*derivs)(xh,yt,dym);
            for (i=0;i<n;i++) {
                    yt[i]=y[i]+h*dym[i];
                    dym[i] += dyt[i];
            }
            (*derivs)(x+h,yt,dyt);
            for (i=0;i<n;i++)
                    yout[i]=y[i]+h6*(dydx[i]+dyt[i]+2.0*dym[i]);
            free_vector(yt);
            free_vector(dyt);
            free_vector(dym);
    }
    //===========================================================================
     
    #define PGROW -0.20
    #define PSHRNK -0.25
    #define FCOR 0.06666666         /* 1.0/15.0 */
    #define SAFETY 0.9
    #define ERRCON 6.0e-4
     
    void  rkqc(double *y, double *dydx, int n, double *x, double htry,
                    double eps, double *yscal, double *hdid, double *hnext,
                    void (*derivs)(double,double *,double *))
    {
            int i;
            double xsav,hh,h,temp,errmax;
            double *dysav,*ysav,*ytemp;
     
     
            dysav=vector(n);
            ysav=vector(n);
            ytemp=vector(n);
            xsav=(*x);
            for (i=0;i<n;i++) {
                    ysav[i]=y[i];
                    dysav[i]=dydx[i];
            }
            h=htry;
            for (;;) {
                    hh=0.5*h;
                    rk4(ysav,dysav,n,xsav,hh,ytemp,derivs);
                    *x=xsav+hh;
                    (*derivs)(*x,ytemp,dydx);
                    rk4(ytemp,dydx,n,*x,hh,y,derivs);
                    *x=xsav+h;
                    if (*x == xsav) nrerror("Step size too small in routine RKQC");
                    rk4(ysav,dysav,n,xsav,h,ytemp,derivs);
                    errmax=0.0;
                    for (i=0;i<n;i++) {
                            ytemp[i]=y[i]-ytemp[i];
                            temp=fabs(ytemp[i]/yscal[i]);
                            if (errmax < temp) errmax=temp;
                    }
                    errmax /= eps;
                    if (errmax <= 1.0) {
                            *hdid=h;
                            *hnext=(errmax > ERRCON ?
                                    SAFETY*h*exp(PGROW*log(errmax)) : 4.0*h);
                            break;
                    }
                    h=SAFETY*h*exp(PSHRNK*log(errmax));
            }
            for (i=0;i<n;i++) y[i] += ytemp[i]*FCOR;
            free_vector(ytemp);
            free_vector(dysav);
            free_vector(ysav);
    }
     
    #undef PGROW
    #undef PSHRNK
    #undef FCOR
    #undef SAFETY
    #undef ERRCON
    //===========================================================================
     
    #define MAXSTP 10000
    #define TINY 1.0e-30
     
    int kmax=0,kount=0;  /* defining declaration */
    double *xp=0,**yp=0,dxsav=0;  /* defining declaration */
     
    int  odeint(double *ystart, int nvar, double x1, double x2, double eps,
                    double h1, double hmin, int *nok, int *nbad,
                    void (*derivs)(double,double *,double *))
    {
            int nstp,i;
            double xsav,x,hnext,hdid,h;
            double *yscal,*y,*dydx;
     
     
            yscal=vector(nvar);
            y=vector(nvar);
            dydx=vector(nvar);
            x=x1;
            h=(x2 > x1) ? fabs(h1) : -fabs(h1);
            *nok = (*nbad) = kount = 0;
            for (i=0;i<nvar;i++) y[i]=ystart[i];
            if (kmax > 0) xsav=x-dxsav*2.0;
            for (nstp=1;nstp<=MAXSTP;nstp++) {
                    (*derivs)(x,y,dydx);
                    for (i=0;i<nvar;i++)
                            yscal[i]=fabs(y[i])+fabs(dydx[i]*h)+TINY;
                    if (kmax > 0) {
                            if (fabs(x-xsav) > fabs(dxsav)) {
                                    if (kount < kmax-1) {
                                            xp[++kount]=x;
                                            for (i=0;i<nvar;i++) yp[i][kount]=y[i];
                                            xsav=x;
                                    }
                            }
                    }
                    if ((x+h-x2)*(x+h-x1) > 0.0) h=x2-x;
                    rkqc(y,dydx,nvar,&x,h,eps,yscal,&hdid,&hnext,derivs);
                    if (hdid == h) ++(*nok); else ++(*nbad);
                    if ((x-x2)*(x2-x1) >= 0.0) {
                            for (i=0;i<nvar;i++) ystart[i]=y[i];
                            if (kmax) {
                                    xp[++kount]=x;
                                    for (i=0;i<nvar;i++) yp[i][kount]=y[i];
                            }
                            free_vector(dydx);
                            free_vector(y);
                            free_vector(yscal);
                            return 0;
                    }
                    if (fabs(hnext) <= hmin) nrerror("Step size too small in ODEINT");
                    h=hnext;
            }
            nrerror("Too many steps in routine ODEINT");
            return 1;
    }
    #undef MAXSTP
    #undef TINY
    //=================================================================
     
    void RungeKutta(double *y, int N,double t1,double t2,void (*derivs)(double,double *,double *) )
    {
            int nok,nbad;
            odeint(y,N, t1, t2,1e-4,1e-2,0,&nok,&nbad,derivs);
    }
    merci d'avance

  4. #4
    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
    Points : 13 017
    Points
    13 017
    Par défaut
    Salut,
    Il y a beaucoup de chose qui ne vont pas dans le code que tu montres. Erreurs de copier/coller ou bases du langage non acquises ?

    A titre d'exemple :
    MonSystem.h :
    -> il n'y a aucun ';' à la fin de la déclaration des fonctions et de la définition de la classe.
    -> que vient faire la liste d'initialisation dans la déclaration du constructeur ( MonSystem() : DynamicalSystem(4)) ?
    -> que vient faire la ligne class DynamicalSystem; après l'inclusion du fichier d'en-tête correspondant ?
    -> C'est DynamicalSystem qui devrait avoir un constructeur public et virtuel (ou protégé si non public) et pas seulement MonSystem.

    Dans MonSystem::Integrator, l'appel à RungeKutta est incorrect pour le premier paramètre qui est un pointeur (pointeur ou tableau ?). '&' permet de récupérer l'adresse d'une variable, '*' permet de déréférencer le pointeur. *y ne signifie rien dans ce contexte d'appel.

    Tu devrais apprendre std::vector et massivement l'utiliser pour éviter les allocations dynamiques.
    Tu devrais t'intéresser à std::string pour les chaînes à la place des tableaux de caractères (qui devrait à minima être des char const *).

    etc...
    Bon courage.

Discussions similaires

  1. Problèmes avec classes et pointeurs
    Par Anas1984 dans le forum C++
    Réponses: 2
    Dernier message: 02/11/2006, 12h49
  2. Help ! probleme avec classe derivee
    Par marcozar dans le forum C++
    Réponses: 2
    Dernier message: 06/09/2006, 15h56
  3. probleme avec l'erreur 3059
    Par el_quincho dans le forum Access
    Réponses: 1
    Dernier message: 07/03/2006, 08h41
  4. probleme avec une erreure!!
    Par d-a-v-e dans le forum C++
    Réponses: 3
    Dernier message: 09/02/2006, 21h15

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