Probleme de complilation urgent

Fermé
beno-yac Messages postés 96 Date d'inscription samedi 11 décembre 2010 Statut Membre Dernière intervention 16 décembre 2020 - 30 nov. 2012 à 13:06
Char Snipeur Messages postés 9813 Date d'inscription vendredi 23 avril 2004 Statut Contributeur Dernière intervention 3 octobre 2023 - 3 déc. 2012 à 08:20
Bonjour,
j'ai une class dauphin qui herite de animal ,poisson et mamifere mais il ya une problemequi est que ça ne veut pas marcher ça me dit undefiende reference to'vtable Dauphin'
voila mon code source C++ .cpp et .h

/*
 * Animal.h
 *
 *  Created on: 23 nov. 2012
 *      Author: ie07095
 */

#ifndef ANIMAL_H_
#define ANIMAL_H_
#include <string>
using namespace std;

class Animal
{
	private:
		string nom;
		bool n;
		int x,y;
	public:
		Animal(string,int,int,bool);
		virtual ~Animal();
		void setNom(string);
		void setN(bool);
		void setX(int);
		void setY(int);
		string getNom();
		int getY();
		int getX();
		bool getN();
		virtual void dep();
		virtual Animal* eng();

};

#endif /* TP9_H_ */


/*
 * Animal.cpp
 *
 *  Created on: 23 nov. 2012
 *      Author: ie07095
 */
#include"Animal.h"
#include <iostream>
#include <string>
using namespace std;

Animal::Animal(string NOM,int A,int B,bool C):nom(NOM),x(A), y(B),n(C)
		{
cout<<"constructeur d'animal"<<endl;

}


 Animal::~Animal(){
cout<<"+++++Destructeur d'animal ++++++"<<endl;

}

void Animal::setX(int abs){
	this->x=abs;
}

void Animal::setY(int cod){
	this->y=cod;
}

void Animal::setN(bool f){
	this->n=f;
}

void Animal::setNom(string name){
	this->nom=name;
}

int Animal::getY(){
	return y;

}

int Animal::getX(){
	return x;

}

string Animal::getNom(){
	return nom;

}

bool Animal::getN(){
	return n;

}



/*
 * Mam.h
 *
 *  Created on: 23 nov. 2012
 *      Author: ie07095
 */

#ifndef MAM_H_
#define MAM_H_
#include"Animal.h"
using namespace std;

class Mam : public Animal {
	private:
	int vitesse;

	public:
	Mam(string,int,int,bool,int );
    //Mam();
	virtual~Mam();
	void dep();
	Mam* eng();
	int getVitesse();
	void setVitesse(int);

};

#endif /* MAM_H_ */


/*
 * Mam.cpp
 *
 *  Created on: 23 nov. 2012
 *      Author: ie07095
 */
#include"Animal.h"
#include"Mam.h"
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

Mam::Mam(string n1,int x1,int y1,bool b1,int p1):Animal(n1,x1,y1,b1),vitesse(p1)
	{
/*
		cout<<"++++++constucteur mammifere+++++"<<endl;
		cout<<"quelle est ça vitesse "<<endl;
		int vite=0;
		cin>>vite;
		vitesse=vite;
*/
	}
/*
Mam::Mam(){

}*/
Mam::~Mam()
	{

		cout<<"+++++destructeur mammifere++++++"<<endl;
	}


 int Mam::getVitesse()
 	 {
	 	 return vitesse;
 	 }

 void Mam::setVitesse(int vite)
 	 {
	 	 this->vitesse=vite;
 	 }

void Mam::dep(){
	setX(getX()+vitesse);
	setY(getY()+vitesse);

 }

 Mam* Mam::eng()
 {
	 if(getN())
	 {
/*		 Mam* p=new Mam();
		p->setNom(getNom()+"_fils");
		p->setX(getX());
		p->setY(getY());*/
		int v1;
		bool femelle;
		v1= ((double)rand ()/(double)RAND_MAX)*2.;
		if(v1==0)
		{femelle=true;
		//			p->setN(true);
		}
		else
		{femelle=false;
			//	p->setN(false);
		}
		 Mam* p=new Mam(getNom()+"_fils",getX(),getY(),femelle,getVitesse());
	 p->setVitesse(getVitesse());
	 return p;
	 }
	 else
	 {
		cout<<"c'est un male donc impossible d'engendrai"<<endl;
		return NULL;
	 }


 }


/*
 * Poisson.h
 *
 *  Created on: 23 nov. 2012
 *      Author: ie07095
 */

#ifndef POISSON_H_
#define POISSON_H_
#include"Animal.h"
using namespace std;

class Poisson:  public Animal {

	private:
		int profondeur;

	public:
			Poisson(string,int,int,bool,int );
			Poisson();
			virtual~Poisson();
			int getPro();
			void setPro(int);
			 void dep();
			 Poisson* eng();

};


#endif /* POISSON_H_ */


/*
 * Poisson.cpp
 *
 *  Created on: 23 nov. 2012
 *      Author: ie07095
 */
#include"Animal.h"
#include"Poisson.h"
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

Poisson::Poisson(string n_,int x_,int y_,bool b_,int p_):Animal(n_,x_,y_,b_),profondeur(p_){
/*	cout<<"le constructeur de poisson"<<endl;
	cout<<"donnez la profondeur du poisson"<<endl;
			int pro=0;
		profondeur=pro;
*/
}
/*
Poisson::Poisson(){

}*/

Poisson::~Poisson(){

	cout<<"Destructeur poisson"<<endl;
}


int Poisson::getPro(){
	return profondeur ;
}

void Poisson::setPro(int a){
	this->profondeur=a;
}

void Poisson::dep(){
	setX(getY()+1);
	setY(getY()+1);
}

Poisson* Poisson::eng(){

		 if(getN())
		 {
			/*Poisson* p=new Poisson();
			p->setNom(getNom()+"_fils");
			p->setX(getX());
			p->setY(getY());*/
			int v1;
			bool femme=true;
			v1= ((double)rand ()/(double)RAND_MAX)*2.;
			if(v1==0)
			{
				femme=true;
				//p->setN(true);
			}
			else
			{
				femme=false;
				//p->setN(false);
			}

		Poisson* p=new Poisson(getNom()+"_fils",getX(),getY(),femme,getPro());
		p->setPro(getPro());
		 return p;
		 }
		 else
		 {
			cout<<"c'est un male donc impossible d'engendrai"<<endl;
			return NULL;
		 }



}




/*
 * Dauphin.h
 *
 *  Created on: 23 nov. 2012
 *      Author: ie07095
 */

#ifndef DAUPHIN_H_
#define DAUPHIN_H_
#include"Animal.h"
#include"Mam.h"
#include"Poisson.h"
using namespace std;

class Dauphin: public Poisson , public Mam{

	public:
	 Dauphin(string,int,int,bool,int,int);
	 virtual ~Dauphin();
	 void afficher();
	 Dauphin* eng();
	 void dep();

};

#endif /* DAUPHIN_H_ */


/*
 * Dauphin.cpp
 *
 *  Created on: 23 nov. 2012
 *      Author: ie07095
 */
#include"Dauphin.h"
#include <iostream>
#include <string>
using namespace std;

Dauphin::Dauphin(string name,int abs, int cor, bool b, int v, int p):Animal(name,abs,cor,b),Poisson(name,abs,cor,b,p),Mam(name,abs,cor,b,v)
	 {
	cout<<"constructeur de dauphin"<<endl;

	 }

void Dauphin::afficher(){
	cout<<"Carte d'identité d'un dauphin"<<endl;
	cout<<"nom :"<<Poisson::getNom()<<endl;
	cout<<"possition :"<<Poisson::getX()<<Poisson::getY()<<endl;
	cout<<"profondeur :"<<getPro()<<endl;
	cout<<"vitesse :"<<getVitesse()<<endl;
}


/*
 * main.cpp
 *
 *  Created on: 23 nov. 2012
 *      Author: ie07095
 */
#include"Poisson.h"
//#include"Dauphin.h"
 int main(){
	// Dauphin flipper("flipper",0,0,true,12,25);
	 //flipper.afficher();
	//Dauphin *petit_flipper=flipper.eng(flipper.estFemale);
	 //petit_flipper->afficher();
	 return 0;
 }


Merci de m'aider j'ai toute essayé je ne sais plus quoi faire de plus

1 réponse

Char Snipeur Messages postés 9813 Date d'inscription vendredi 23 avril 2004 Statut Contributeur Dernière intervention 3 octobre 2023 1 297
30 nov. 2012 à 14:34
Salut.
J'ai comme erreur de compilation :
type 'class Animal' is not a direct base of 'Dauphin'
ce qui est logique.
Si je corrige, j'ai plein d'erreur au niveau des fonctions membres de Dauphin, eng et dep.
si je commente ces fonctions dans le .h, j'ai un problème avec ces fonction dans la classe Animal, je les rend virtuelle pure (=0).
Et après, pas de problème de compilation.
je decommente flipper : ça fonctionne. Pas petit_flipper en revanche.
1
beno-yac Messages postés 96 Date d'inscription samedi 11 décembre 2010 Statut Membre Dernière intervention 16 décembre 2020
2 déc. 2012 à 23:06
Tout d'abord merci Beaucoup pour ton aide .
Mais j'ai pas très bien compris comment tu rends les deux fct VIRTUELLE PURE???
0
beno-yac Messages postés 96 Date d'inscription samedi 11 décembre 2010 Statut Membre Dernière intervention 16 décembre 2020
2 déc. 2012 à 23:17
dans la classe Animal.h j'ai fait ça
virtual void dep() =0;
virtual Animal* eng()=0;
se qui fait que les deux Fonctions sont virtuelle pure mais il me reste un probleme quand je fait l'heritage au niveau de la classe dauphin.cpp,il me donne comme erreur de compilation :
" erreur: type 'Animal' is not a direct base of 'Dauphin' " donc je ne comprends pas dauphin Herite des deux classes poisson et Mam (mammifère ) qui eux meme héritent de Animal donc je ne comprends pas .
0
Char Snipeur Messages postés 9813 Date d'inscription vendredi 23 avril 2004 Statut Contributeur Dernière intervention 3 octobre 2023 1 297
3 déc. 2012 à 08:20
Pour être plus clair, Animal n'est pas mère de Duaphin, mais grand mère. Du coup tu ne peux pas l'appeler, et de toute manière, ça ne sert à rien, la construction devant logiquement être faite dans les classes mères. Il suffit de virer Animal du constructeur de Dauphin.
0