Code:
#include <iostream>
#include <vector>
class Animal
{
public:
virtual void Movement()
{
}
virtual void Eat()
{
}
};
class Mammals : public Animal
{
public:
void Movement()
{
cout << "I use my legs!" << endl;
}
void Eat()
{
cout << "I eat anything I can find!" << endl;
}
};
class Reptiles : public Animal
{
public:
void Movement()
{
cout << "I use my legs and slither!" << endl;
}
void Eat()
{
cout << "I usually eat meat!" << endl;
}
};
class Birds : public Animal
{
public:
void Movement()
{
cout << "I fly for the most part, some of the oddballs walk!" << endl;
}
void Eat()
{
cout << "I usually eat meat!" << endl;
}
};
class Amphibians : public Animal
{
public:
void Movement()
{
cout << "I generally crawl with my legs, and slither, AND swim!" << endl;
}
void Eat()
{
cout << "I usually eat meat!" << endl;
}
};
class Fishes : public Animal
{
public:
void Movement()
{
cout << "You guessed it, I swim! (some of us get beached though, stupid fat whales!)" << endl;
}
void Eat()
{
cout << "I eat anything I can find in the water!" << endl;
}
};
void operateAnimals(vector<Animal*> Animals)
{
for(int i=0; i<Animals.size(); i++)
{
//This is where the interesting stuff happens:
Animals[i]->Movement();
Animals[i]->Eat();
}
}
int main()
{
Animal allAnimals;
Mammals Mammal;
Reptiles Reptile;
Birds Bird;
Amphibians Amphibian;
Fishes Fish;
vector<Animal*> Animals;
Animals.push_back(&Mammals);
Animals.push_back(&Reptile);
Animals.push_back(&Bird);
Animals.push_back(&Bird);
Animals.push_back(&Amphibian);
Animals.push_back(&Fish);
operateAnimals(Animals);
return 0;
}
Lotsa errors, here they are, when i make it include <iostream> couts and stuff are undeclared, and it seems that it isnt taking vector either?
Code:
--------------------Configuration: Practice with OOP - Win32 Debug--------------------
Compiling...
Practice.cpp
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(22) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(22) : error C2297: '<<' : illegal, right operand has type 'char [15]'
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(22) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(26) : error C2297: '<<' : illegal, right operand has type 'char [27]'
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(83) : error C2065: 'vector' : undeclared identifier
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(83) : error C2059: syntax error : '>'
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(84) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(84) : error C2447: missing function header (old-style formal list?)
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(103) : error C2059: syntax error : '>'
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(104) : error C2065: 'Animals' : undeclared identifier
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(104) : error C2228: left of '.push_back' must have class/struct/union type
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(104) : error C2275: 'Mammals' : illegal use of this type as an expression
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(17) : see declaration of 'Mammals'
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(105) : error C2228: left of '.push_back' must have class/struct/union type
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(106) : error C2228: left of '.push_back' must have class/struct/union type
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(107) : error C2228: left of '.push_back' must have class/struct/union type
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(108) : error C2228: left of '.push_back' must have class/struct/union type
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(109) : error C2228: left of '.push_back' must have class/struct/union type
c:\documents and settings\jonathan\my documents\c++ programming\opengl with nehe\nehe tutorials\practice with oop\practice.cpp(111) : error C2065: 'operateAnimals' : undeclared identifier
Error executing cl.exe.
Practice with OOP.exe - 18 error(s), 0 warning(s)