dimanche 8 mars 2015

Why cout complaining when calling a function from an object of other class?

I have these composition classes below. Problem is, in Elephant.cpp, the line: cout<<"Elephant do: \n"<


Practice62.cpp this is the main class



#include < iostream >
#include "Animal.h"
#include "Elephant.h"

int main()
{
Animal an;
Elephant el(an);
el.shout();

}


// Animal.cpp: animal class



#include "Animal.h"
#include <iostream>

using namespace std;

Animal::Animal()
{
cout<<"Animal constructor"<<endl;
}

void Animal::eats()
{
cout<<"eats"<<endl;
}
void Animal::sleeps()
{
cout<<"sleeps"<<endl;
}

//Animal.h Animal header

#ifndef ANIMAL_H
#define ANIMAL_H
class Animal
{
public:
Animal();
void eats();
void sleeps();

};


//Elephant.cpp Elephant class definition

#include <iostream>
#include "Elephant.h"
#include "Animal.h"

using namespace std;

Elephant::Elephant(Animal an)
: animal(an)
{
}

void Elephant::shout()
{
cout<<"Elephant do: \n"<<animal.eats();

}


// Elephant.h: Elephant header



#ifndef ELEPHANT_H
#define ELEPHANT_H
#include <iostream>
#include "Animal.h"

using namespace std;

class Elephant
{
public:
Elephant(Animal an);
void shout();
private:
Animal animal;
};
#endif


Can someone explain why cout won't accept this calling of function within <


Aucun commentaire:

Enregistrer un commentaire