héritage - classes abstraites
Bonjour, j'ai quelques soucis concernant les héritages, mais le pire, c'est que je ne comprend pas mes erreurs :cry:
J'ai en tout 3 classes mères: Schema_MSTZ (qui a pour fille Schema_MSTZ_Euler), Resolution_MSTZ (qui a pour fille Resolution_MSTZ_brut), et Probleme (qui n'a pas encore de filles).
Dans ma classe Probeme, je mets en paramètres 2 pointeurs des 2 autres classes mères (auquel je leurs appliquent un "new".
Comme ça, chaque problème pourra être résolu grâce à un schéma et avec un type de résolution (comme l'indiquent les noms).
Le fichier "lib_func.h" que je charge fait partie d'une librairie.
Voici mes classes:
Schema_mstz.h
Code:
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
|
#ifndef _SCHEMA_MSTZ_
#define _SCHEMA_MSTZ_
#include "probleme.h"
#include "lib_fonc.h"
class Schema_MSTZ {
protected:
//int dim, N, p,iter;
int p,dim;
Probleme *prob;
public:
Schema_MSTZ() {}
Probleme*& get_probleme(){return prob;}
virtual DbleVect A(double t,double dt,const DbleVect& X) const {std::cout<<"Fonction A not defined";abort();}
virtual DbleVect A2(double t1,double t2,double t,const DbleVect& X1,const DbleVect& X2,double dt,const DbleVect& psi) {std::cout<<"Fonction A2 not defined";abort();}
DbleVect b(double t1,double t2,double t,const DbleVect& X1, const DbleVect& X2,const DbleVect& psi,int dim);
int get_dim() const {return dim;}
int get_p() const {return p;}
};
#endif |
Schema_mstz.cc
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include "schema_mstz.h"
using namespace std;
DbleVect Schema_MSTZ::b(double t1,double t2,double t,const DbleVect& X1, const DbleVect& X2,const DbleVect& psi,int dim=1) {
DbleVect X_tilde(dim); X_tilde.zero();
double dt=t2-t1;
DbleVect alpha(dim); alpha.zero();
DbleVect beta(dim); beta.zero();
// alpha.add(1./dt,_X_barre[i], 1./dt,_X_barre[i+1]); //alpha=(X1-X2)/(t1-t2)
alpha.add(1./dt,X2, -1./dt,X1); //alpha=(X2-X1)/(t2-t1)
// beta.add(1.0,_X_barre[i], -_tau[i], alpha); //beta=X1-t1*alpha
beta.add(1.0,X1, -t1, alpha); //beta=X1-t1*alpha
X_tilde.add(t,alpha, 1.0, beta); //fonction y=t*alpha+beta
DbleVect Z(dim); Z.zero();DbleVect y(dim);
Z.add(-1.0,psi);
DbleMat A=prob->DaT(t,X_tilde);
A.ProductVector(y,Z);
return y;
} |
Schema_mstz.h (sous classe de Schema_MSTZ)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#ifndef _SCHEMA_MSTZ_EULER_
#define _SCHEMA_MSTZ_EULER_
#include "schema_mstz.h"
#include "lib_fonc.h"
class Schema_MSTZ_Euler : public Schema_MSTZ {
private:
int p;
public:
Schema_MSTZ_Euler(){p=1;}
DbleVect A(double t,double dt,const DbleVect& X) const;
DbleVect A2(double t1,double t2,double t,const DbleVect& X1,const DbleVect& X2,double dt,const DbleVect& psi) ;
};
#endif |
Schema_mstz.cc
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| #include "schema_mstz_euler.h"
using namespace std;
DbleVect Schema_MSTZ_Euler::A(double t,double dt,const DbleVect& X) const {
DbleVect y(X);
y=X; y.add(dt,prob->a(t,X));
return y;
}
/************************************************************************************************************************/
/************************************************************************************************************************/
DbleVect Schema_MSTZ_Euler::A2(double t1,double t2,double t,const DbleVect& X1,const DbleVect& X2,double dt,const DbleVect& psi) {
int d=psi.size();
DbleVect y(psi);
y=psi; y.add(dt,b(t1,t2,t,X1,X2,psi,d));
return y;
} |
resolution_mstz.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #ifndef _RESOLUTION_MSTZ_
#define _RESOLUTION_MSTZ_
#include "lib_fonc.h"
#include "schema_mstz_euler.h"
class Resolution_MSTZ {
protected:
std::vector<double> tau, param;
std::vector<DbleVect> X_barre, erreur, psi;
double t1,t2;
DbleVect X1,X2;
public:
virtual void run(double TOL, double Tf,const DbleVect& X0, int N0, DbleVect dg(DbleVect), DbleMat DaT(double,DbleVect), std::string demipas) const {std::cout<<"Fonction run not defined";abort();}
};
#endif |
probleme.h
Code:
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
|
#ifndef _PROBLEME_
#define _PROBLEME_
//divers #include
#include "schema_mstz.h"
#include "resolution_mstz.h"
class Probleme {
protected:
int dim;
Resolution_MSTZ * myresolution;
Schema_MSTZ * myschema;
public:
//Probleme(){}
Schema_MSTZ*& get_schema() {return myschema;} //pour appliquer un "new"
Resolution_MSTZ*& get_resolution(){return myresolution;} //pour appliquer un "new"
virtual DbleVect a(double,DbleVect) const {std::cout<<"Fonction a not defined";abort();}
virtual DbleMat DaT(double,DbleVect) const {std::cout<<"Fonction DaT not defined";abort();}
virtual DbleVect solution(double) const {std::cout<<"Fonction solution not defined";abort();}
virtual void plot (std::string f_solution, std::string f_psi, std::string f_erreur, std::string f_pas_temps) const {std::cout<<"Fonction plot not defined";abort();}
virtual void plot_lorenz(std::string f_solution, std::string f_3d) const {std::cout<<"Fonction plot_lorenz not defined";abort();}
virtual void plot_turbulence(std::string f_pouce, std::string f_psi2d) const {std::cout<<"Fonction plot_turbulence not defined";abort();}
virtual double error () const {std::cout<<"Fonction error not defined";abort();}
};
#endif |
Mes erreurs:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
In file included from /home/romain/Bureau/ConchaBase_Etud/Projects/EquaDiff/src/resolution_mstz.h:5,
from /home/romain/Bureau/ConchaBase_Etud/Projects/EquaDiff/src/probleme.h:13,
from /home/romain/Bureau/ConchaBase_Etud/Projects/EquaDiff/src/schema_mstz.h:4,
from /home/romain/Bureau/ConchaBase_Etud/Projects/EquaDiff/src/schema_mstz.cc:1:
/home/romain/Bureau/ConchaBase_Etud/Projects/EquaDiff/src/schema_mstz_euler.h:7: erreur: expected class-name before «{» token
In file included from /home/romain/Bureau/ConchaBase_Etud/Projects/EquaDiff/src/schema_mstz.h:4,
from /home/romain/Bureau/ConchaBase_Etud/Projects/EquaDiff/src/schema_mstz.cc:1:
/home/romain/Bureau/ConchaBase_Etud/Projects/EquaDiff/src/probleme.h:25: erreur: ISO C++ forbids declaration of «Schema_MSTZ» with no type
/home/romain/Bureau/ConchaBase_Etud/Projects/EquaDiff/src/probleme.h:25: erreur: expected «;» before «*» token
/home/romain/Bureau/ConchaBase_Etud/Projects/EquaDiff/src/probleme.h:31: erreur: ISO C++ forbids declaration of «Schema_MSTZ» with no type
/home/romain/Bureau/ConchaBase_Etud/Projects/EquaDiff/src/probleme.h:31: erreur: expected «;» before «*» token
/home/romain/Bureau/ConchaBase_Etud/Projects/EquaDiff/src/probleme.h:33: erreur: expected `;' before «Resolution_MSTZ» |