简体   繁体   中英

C++ push_back compiler error "

I am trying to add a struct to a vector of structs.

    vector<udtWChar2> n;
    vector<udtTag>_tags;

for (unsigned t=0;t<_tags.size();t++)
{
    udtTag &nt=_tags[t];
    for (int i=nt.PosStartTag;i<nt.PosStartTag+nt.CoveredLen;i++)
    {
        n[i].Tags.push_back[nt];
    }
}

The error I am getting is in the line

 n[i].Tags.push_back[nt];

"A pointer to a bound function may only be called to invoke the function".

Here are my declarations:

struct udtTag
{
    int PosStartTag;
    int LenStartStart;
    int PosEndTag;
    int LenEndTag;
    int CoveredLen;
    eTagType Type;
    wstring Value;
};

struct udtWChar2
{
    wstring Text;
    int OrigPos;
    int AbsSpeed;
    int Bookmark;
    bool IsTag;
    vector<udtTag>Tags;
};

I don't see what I did wrong. Can somebody please help? Thank you.

The expression Tags.push_back[nt] is not a call of method push_back . The compiler thinks you want to call push_back.operator[] . Replace the square brackets with parentheses:

... Tags.push_back(nt);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM