error: invalid lvalue in assignment

Discussion in 'C++' started by mundacho@gmail.com, Jan 23, 2009.

  1. Guest

    Hello,

    I'm getting this error:

    ../templates.hpp: In function 'Img crop(const Img&, const
    cvmlcpp::iPoint2D&, const cvmlcpp::iPoint2D&) [with Img =
    ili::BWImg]':
    RectangleImageComparator.cc:85: instantiated from here
    ../templates.hpp:61: error: invalid lvalue in assignment

    What's weird is that exactly the same template works with another
    image type, as in the file where I instantiate it I have:

    -------- begin extract RectangleImageComparator.cc -------
    84 IntImg rectImg = crop<IntImg>(tempImage, corners[0],
    corners[2]); // this function instantiates correctly
    85 BWImg rectBWI = crop<BWImg>(bwImage, corners[0],
    corners[2]); // if I eliminate this line (and all that uses the
    result) all the code works
    -------- end extract RectangleImageComparator.cc -------

    The images are template classes defined like this:


    typedef cvmlcpp::Matrix<bool , 2u> BWImg;
    typedef cvmlcpp::Matrix<int_t, 2u> IntImg;

    So, why would the instantiation work with the int version and not with
    the boolean?? What does it mean the "error: invalid lvalue in
    assignment", why does it appear only in the instantiation on the
    boolean img??

    Thanks for your help,

    eD


    -------- begin extract templates.hpp -------

    29 template <class Img>
    30 Img crop(const Img &img, const cvmlcpp::iPoint2D &ulc,
    31 const cvmlcpp::iPoint2D &brc)
    32 {
    33 typedef typename Img::value_type T;
    34
    35
    36 // check for valid arguments
    37 // the image itself will take care of the out of bound
    exception
    38
    39 /// \todo TODO put this function in the library
    40 unsigned newHeight = ((brc[0] - ulc[0]) > 0) ? (brc[0] - ulc
    [0]) : 0;
    41 unsigned newWidth = ((brc[1] - ulc[1]) > 0) ? (brc[0] - ulc
    [0]) : 0;
    42
    43 if (newHeight == 0)
    44 {
    45 std::invalid_argument myException("Height");
    46 throw myException;
    47 }
    48 else if (newWidth == 0)
    49 {
    50 std::invalid_argument myException("Width");
    51 throw myException;
    52 }
    53
    54 Img myImage = ili::init<Img>(newHeight, newWidth);
    55
    56 // now we do the copying
    57 for (unsigned i = 0; i < newHeight; i++)
    58 {
    59 for (unsigned j = 0; j < newWidth; j++)
    60 {
    61 myImage[j] = img[ulc[0] + i][ulc[1] + j]; // this
    would be the line
    62 }
    63 }
    64
    65 return myImage;
    66 }
    , Jan 23, 2009
    #1
    1. Advertising

  2. Kai-Uwe Bux Guest

    wrote:

    > Hello,
    >
    > I'm getting this error:
    >
    > ./templates.hpp: In function 'Img crop(const Img&, const
    > cvmlcpp::iPoint2D&, const cvmlcpp::iPoint2D&) [with Img =
    > ili::BWImg]':
    > RectangleImageComparator.cc:85: instantiated from here
    > ./templates.hpp:61: error: invalid lvalue in assignment
    >
    > What's weird is that exactly the same template works with another
    > image type, as in the file where I instantiate it I have:
    >
    > -------- begin extract RectangleImageComparator.cc -------
    > 84 IntImg rectImg = crop<IntImg>(tempImage, corners[0],
    > corners[2]); // this function instantiates correctly
    > 85 BWImg rectBWI = crop<BWImg>(bwImage, corners[0],
    > corners[2]); // if I eliminate this line (and all that uses the
    > result) all the code works
    > -------- end extract RectangleImageComparator.cc -------
    >
    > The images are template classes defined like this:
    >
    >
    > typedef cvmlcpp::Matrix<bool , 2u> BWImg;
    > typedef cvmlcpp::Matrix<int_t, 2u> IntImg;
    >
    > So, why would the instantiation work with the int version and not with
    > the boolean??

    [snip]

    I am going to take a wild guess here since you failed to post enough code to
    reproduce the problem: Could it be that your cvmlcpp::Matrix<T,N> template
    uses a vector<T> internally? In that case, beware that vector<bool> is a
    specialization that obeys peculiar rules. In particular, operator[] and the
    like to not return references but proxies.


    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Jan 24, 2009
    #2
    1. Advertising

  3. Guest

    On 24 ene, 07:04, Kai-Uwe Bux <> wrote:
    > wrote:
    > > Hello,

    >
    > > I'm getting this error:

    >
    > > ./templates.hpp: In function 'Img crop(const Img&, const
    > > cvmlcpp::iPoint2D&, const cvmlcpp::iPoint2D&) [with Img =
    > > ili::BWImg]':
    > > RectangleImageComparator.cc:85:   instantiated from here
    > > ./templates.hpp:61: error: invalid lvalue in assignment

    >
    > > What's weird is that exactly the same template works with another
    > > image type, as in the file where I instantiate it I have:

    >
    > > -------- begin extract RectangleImageComparator.cc -------
    > >  84             IntImg rectImg = crop<IntImg>(tempImage, corners[0],
    > > corners[2]); // this function instantiates correctly
    > >  85             BWImg  rectBWI = crop<BWImg>(bwImage, corners[0],
    > > corners[2]); // if I eliminate this line (and all that uses the
    > > result) all the code works
    > > -------- end extract RectangleImageComparator.cc -------

    >
    > > The images are template classes defined like this:

    >
    > > typedef cvmlcpp::Matrix<bool , 2u> BWImg;
    > > typedef cvmlcpp::Matrix<int_t, 2u> IntImg;

    >
    > > So, why would the instantiation work with the int version and not with
    > > the boolean??

    >
    > [snip]
    >
    > I am going to take a wild guess here since you failed to post enough code to
    > reproduce the problem: Could it be that your cvmlcpp::Matrix<T,N> template
    > uses a vector<T> internally? In that case, beware that vector<bool> is a
    > specialization that obeys peculiar rules. In particular, operator[] and the
    > like to not return references but proxies.
    >
    > Best
    >
    > Kai-Uwe Bux


    Wow!!! I've just checked and in fact, cvmlcpp uses vector<bool> for
    the matrix implementation!!!
    Thanks a lot!!
    , Jan 24, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. A. Farber
    Replies:
    5
    Views:
    614
    A. Farber
    Oct 6, 2006
  2. Kavya
    Replies:
    9
    Views:
    496
    Dik T. Winter
    Oct 28, 2006
  3. mdh

    invalid lvalue in assignment

    mdh, Oct 28, 2007, in forum: C Programming
    Replies:
    4
    Views:
    353
  4. Replies:
    11
    Views:
    686
    James Kuyper
    Sep 22, 2008
  5. Chad

    invalid lvalue in assignment

    Chad, Jan 9, 2009, in forum: C Programming
    Replies:
    16
    Views:
    984
    Default User
    Jan 10, 2009
Loading...

Share This Page