'=' : left operand must be l-value
<p>When I compile the following code, I got "error C2106: '=' : left operand must be l-value" at "m.msg_body[i].id = i;". When I comment out that line, there is not error. What is wrong with my code?</p>

<pre><code>static const short MSG_DATA_MAX = 10;

struct MsgBodyData
{
    int id;
    string value;
};

class MsgBody
{
public:
    MsgBody()
    {
        len = 0;    
    }
    MsgBody(MsgBody &amp; msg_obj);
    ~MsgBody() {}

    int length() { return len; }
    void setLength(int _len) { len = _len; }

    MsgBodyData operator[](short index)
    {
        if(index &gt; -1 &amp;&amp; index &lt; MSG_DATA_MAX)
            return data[index];

        MsgBodyData dump_data;
        return dump_data;
    }

    void operator=(MsgBody &amp; msg_obj)
    {
        len = msg_obj.length();
        for(int i = 0; i &lt; len; ++i)
            data[i] = msg_obj[i];
    }

private:
    int len;
    MsgBodyData data[MSG_DATA_MAX];
};

MsgBody::MsgBody(MsgBody &amp;msg_obj)
{
    operator=(msg_obj);
}

struct Msg
{
    int msg_id;
    string msg_title;
    MsgBody msg_body;
};


void sendMsg()
{
    Msg m;
    m.msg_id = 1;
    m.msg_title = "test_msg";

    int size = MSG_DATA_MAX;

    for(int i = 0; i &lt; size; ++i)
    {
        m.msg_body[i].id = i;  // HERE I GOT ERROR !!!
        m.msg_body[i].value = "test_value";
    }
}
</code></pre>
