0

I am trying to do this:

class bbb
{
public:
    bbb(std::list<int> lst) { }
};

int main()
{
    bbb b((std::list<int>)boost::assign::list_of<int>(10)(10));
    return 0;
}

and get following error from g++:

some.cc:35: error: call of overloaded 'bbb(boost::assign_detail::generic_list<int>&)' is ambiguous
some.cc:15: note: candidates are: bbb::bbb(std::list<int, std::allocator<int> >)
some.cc:13: note:                 bbb::bbb(const bbb&)

Is there any way to work around this problem? Note that I am using gcc 4.4.6. It doesn't support entire c++11, so I am compiling for c++03.

Thanks...

Alexander Sandler
  • 2,078
  • 2
  • 19
  • 21

1 Answers1

0

The code was compiled by VC++ 2010. I found 2 workarounds for GCC (See code below). I think there are not any difference in code, which will generated by optimised compiler, but I prefer first variant. I do not know the reason why conversion operator does not work. Try to answer on boost forum.

class bbb
{
 public:
   bbb(std::list<int> lst) { }
};

int main()
{
//simplest decision
   std::list<int> tmp = boost::assign::list_of<int>(10)(10);
   bbb b(tmp);
// one line decision
   bbb b3((boost::assign::list_of<int>(10)(10)).operator std::list<int> () );
//compiled by VC++ 2010 !!!
   bbb b4((std::list<int>)(boost::assign::list_of<int>(10)(10)) );

   return 0;
}
SergV
  • 1,269
  • 8
  • 20