vector push_back

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kenneth6
    New Member
    • Mar 2007
    • 79

    vector push_back

    class object {
    public:
    object (string t, string n, int p)
    }
    object item("string1", "string2",5 );
    vector<object *> list;
    item.push_back( item);


    error C2664: 'std::vector<_T y>::push_back' : cannot convert parameter 1 from 'item' to 'object *const &'
    1> with
    1> [
    1> _Ty=SellableIte m *
    1> ]
    1> Reason: cannot convert from 'item' to 'object *const '
    1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


    Why it happened ?
  • scruggsy
    New Member
    • Mar 2007
    • 147

    #2
    Originally posted by kenneth6
    class object {
    public:
    object (string t, string n, int p)
    }
    object item("string1", "string2",5 );
    vector<object *> list;
    item.push_back( item);


    error C2664: 'std::vector<_T y>::push_back' : cannot convert parameter 1 from 'item' to 'object *const &'
    1> with
    1> [
    1> _Ty=SellableIte m *
    1> ]
    1> Reason: cannot convert from 'item' to 'object *const '
    1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


    Why it happened ?
    I am assuming that item.push_back( item) is supposed to be list.push_back( item), right?
    In that case, notice that item is of type object, whereas the vector holds pointers to objects. You may have intended to do list.push_back( &item).

    Comment

    Working...