Problem with push_back.

Discussion in 'C++' started by AnuSree, Oct 28, 2003.

  1. AnuSree

    AnuSree Guest

    Hi



    I am getting error with push_back, some one please help me ASAP in this
    aspect here am sending the needful info.

    _______________

    Class VarbindList:

    _______________



    #ifndef VARBINDLIST_H

    #define VARBINDLIST_H



    #include "Varbind.h"

    #include "Vector.h"

    #include <vector.h>

    #include "Snmp.h"

    #include "Object.h"



    class VarbindList : public Vector {



    public:

    VarbindList() {



    static const string INVALID_OBJ = "Invalid instance";

    static const string INVALID_OBJ_VEC = "Not an instance of vector";

    }

    VarbindList(int initialCapacity);



    static VarbindList decodeSequence(Asn1Value aVarbinds);// throws



    void addVarbind(Object aVarbind);// throw Exception;





    void addVarbinds(vector <Object> aVarbindArray);// throw Exception;





    void addVarbinds(Vector aVectorOfVarbinds);// throw Exception;





    void addVarbinds(Object aVarbind);// throw Exception;





    vector <Varbind> getVarbindArray();

    vector <Object> encode();

    char * toString();



    // Constants

    private:

    static const string INVALID_OBJ;// = "Invalid instance";

    static const string INVALID_OBJ_VEC;// = "Not an instance of vector";

    };

    #endif // VARBINDLIST_H



    ___________________

    Class NameValuePair:

    ___________________



    # ifndef NAMEVALUEPAIR_H

    # define NAMEVALUEPAIR_H



    #include "Snmp.h"

    # include "AllIncludes.h"



    class NameValuePair {

    private:

    string Name;

    string Value;



    public:

    NameValuePair() { }

    NameValuePair(string mName, string mValue) {

    Name = mName;

    Value = mValue;

    }

    //Get methods..

    string name() { return Name; }

    string value() { return Value; }



    //Set Methods

    void name(string mName) { Name = mName; }

    void value(string mValue) { Value = mValue; }

    };

    # endif





    And this is the peice of code of a method in which i am getting error
    when am using push_back.



    Message SnmpSouthAdaptor :: encode(Request req) {



    vector<NameValuePair> ar = req.arr();

    VarbindList varbinds;// = VarbindList();

    for ( int i = 0; i < ar.size(); ++i ) {

    varbinds.push_back(ar); //Error Here

    }

    }





    Here in varbinds.push_back(ar), i have to type cast the type of ar
    from vector<NameValuePair> to the type VarbindList but am not getting
    how to do this,since the type of the ar is not the same as the type
    of varbind am getting error :



    no matching function for call to `VarbindList::push_back
    (NameValuePair &)'





    Here VarbindList is a class and varbinds is the object of the class
    VarbindList and ar is of type vector<NameValuePair>.



    I wrote the class declarations of both VarbindList and NameValuePair on
    the top.Please help me ASAP


    --
    Posted via http://dbforums.com
     
    AnuSree, Oct 28, 2003
    #1
    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. sks_cpp

    inline - push_back

    sks_cpp, Jul 3, 2003, in forum: C++
    Replies:
    2
    Views:
    399
  2. Ganesh Gella
    Replies:
    5
    Views:
    1,287
    John Harrison
    Jul 14, 2003
  3. AnuSree
    Replies:
    2
    Views:
    375
    AnuSree
    Oct 21, 2003
  4. Al
    Replies:
    3
    Views:
    1,626
    Jim Langston
    Dec 26, 2005
  5. JoeC
    Replies:
    5
    Views:
    1,402
Loading...

Share This Page