How to get this to compile?

Posted by ShaChris23 on Stack Overflow See other posts from Stack Overflow or by ShaChris23
Published on 2010-03-16T21:09:41Z Indexed on 2010/03/16 21:11 UTC
Read the original article Hit count: 235

Filed under:

I have this code which compiles and works as expected:

class Right
{};

class Left
{
public:
  Left& operator = (Right const&)
  {
    //... Do something ...

    return *this;
  }
};


int main()
{
  Right right;
  Left left;

  // Assign individual object -- this works
  left = right;
}

But now, this one surprises me, I thought the template would work itself out since I already provided the = operator() to the Left class.

int main()
{
  ...

  std::list<Right> rightLst;
  std::list<Left>  leftLst;

  // Assign a list of objects -- this doesn't compile
  leftLst = rightLst;
}

What can I do so that I could convert the rightLst to leftLst conversion in a single line?

© Stack Overflow or respective owner

Related posts about c++