Greetings everybody!
I searched the board and the google... but couldn't find any help.
So, I hope somebody here does surely have the answer!
I just started with OOP. The following program works fine if I use list or vector class but doesn't work for set. I would wonder why??? gives 9 long errors and 4 warnings. Was supposed to handle the "set" in special way??? Please help!!
Here's the code:
Code:// Cat.h
#ifndef ANIMALS_CAT_H
#define ANIMALS_CAT_H
#include <string>
namespace animals
{
class Cat
{
public:
Cat(std::string _name);
void eat(std::string food);
float weight;
std::string name;
};
}
#endif
Code:
// cat.cpp
#include <iostream>
#include "Cat.h"
using namespace std;
namespace animals
{
Cat::Cat(std::string _name)
{
name = _name;
}
void Cat::eat(string food)
{
cout << name << " says: yum yum! " << food << endl;
}
}
Thank you in advance!Code:
// main.cpp
#include "Cat.h"
#include <set>
//#include <list>
using namespace animals;
typedef std::set <Cat> collection;
//typedef std::list <Cat> collection;
int main(int argc, char* argv, char *envp)
{
collection cats;
//cats.push_back(Cat("Garfield"));
//cats.push_back(Cat("Pussy"));
cats.insert(Cat("Garfield"));
cats.insert(Cat("Pussy"));
for(collection::iterator i=cats.begin(); i!=cats.end(); ++i)
{
(*i).eat("lasagna");
}
return 0;
}