I am trying to create a set of objects. Merely defining the set is giving errors. I do not have a compiler right now with boost. So I used an online IDE. Here is the link to the code http://codepad.org/UsBAMmuh. Somehow, it does not seem to work. Eventually, I would like to pass a reference to this set in the constructor of another class.
#include <iostream>
#include <boost/optional.hpp>
#include <boost/ref.hpp>
#include <boost/serialization/vector.hpp>
using namespace std;
class Fruit {
};
class Env
{
public:
Env(std::set<Fruit>& apples);
std::set<Fruit>& GetApples() const;
void AddApple(Fruit const& fruit);
private:
std::set<Fruit>& _apples;
};
Env::Env(std::set<Fruit>& apples):
_apples(apples)
{
}
std::set<Fruit>& Env::GetApples() const
{
return _apples;
}
void Env::AddApple(Fruit const& fruit)
{
this->_apples.insert(fruit);
}
class EnvHolder{
public:
void SetEnv (Env const& env);
Env& GetEnv()const;
private:
boost::scoped_ptr<Env> _env;
};
void EnvHolder::SetEnv(Env const& env)
{
this->_env.reset(new Env(env));
}
Env& EnvHolder::GetEnv() const
{
return *this->_env;
}
int main() {
std::set<Fruit> fruits;
//Fruit *fr = new Fruit();
//fruits.insert(*fr);
//Env env(fruits);
cout << "Hello" << endl;
return 0;
}
I get the following error:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h: In member function 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Fruit]': /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/boost_concept_check.h:358: instantiated from 'void __gnu_cxx::_BinaryFunctionConcept<_Func, _Return, _First, Second>::_constraints() [with _Func = std::less, _Return = bool, _First = Fruit, _Second = Fruit]' /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_set.h:112: instantiated from '__gnu_norm::set, std::allocator >' /usr/local/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../../include/c++/4.1.2/debug/set.h:45: instantiated from '__gnu_debug_def::set, std::allocator >' t.cpp:35: instantiated from here Line 226: error: no match for 'operator<' in '__x < __y' compilation terminated due to -Wfatal-errors.