473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with push_back,help me ASAP


hi

am getting error when am trying to type cast.is it possible to type
cast from one type of vector to another type.is there any other way
other than overloading.my peice of code in which am getting error is.

Here is my peice of code.

_____________________

vector<Varbind> varbinds;

vector<NameValuePair> nameValuePairs;

if(varbinds.size()!=0) {

for(int index = 0;index<varbinds.size();++index) {

nameValuePairs.push_back(varbinds[index]);

}

}

here i have to cast the type of varbinds from type vector<Varbinds> to
the type vector<NameValuePair>

And the second query is

______________________

it is also with push_back.Here is the peice of code

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

VarbindList varbinds;

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

varbinds.push_back(ar); //Error Here

}

Here varbinds is the object of the class VarbindList and ar is of
type vector<NameValuePair>.I have to cast vector<NameValuePairs> to the
type VarbindList.

Please help me in this to aspects ASAP.
--
Posted via http://dbforums.com
Jul 19 '05 #1
2 2059
"AnuSree" <me*********@dbforums.com> wrote...
am getting error when am trying to type cast.is it possible to type
cast from one type of vector to another type.is there any other way
other than overloading.my peice of code in which am getting error is.

Here is my peice of code.

_____________________

vector<Varbind> varbinds;

vector<NameValuePair> nameValuePairs;

if(varbinds.size()!=0) {

for(int index = 0;index<varbinds.size();++index) {

nameValuePairs.push_back(varbinds[index]);
It is only possible to do this if 'Varbind&' is convertible to
'NameValuePair const&'.

}

}

here i have to cast the type of varbinds from type vector<Varbinds> to
the type vector<NameValuePair>
No, you only have to have 'Varbinds' convertible to 'NameValuePair' but
since you didn't post the definition of either of them, there is no way
to recommed anything in particular.
And the second query is

______________________

it is also with push_back.Here is the peice of code

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

VarbindList varbinds;
What's 'VarbindList'? I'll assume that it's a vector<Varbind>.
Next time please specify.

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

varbinds.push_back(ar); //Error Here
Well, again, you're trying to use 'vector<NameValuePair>' where
a 'Varbind' is expected (under my assumption).

}

Here varbinds is the object of the class VarbindList and ar is of
type vector<NameValuePair>.I have to cast vector<NameValuePairs> to the
type VarbindList.


No, you don't have to cast to 'VarbindList', you only need it to be
convertible to the type '.push_back()' expects.

Next time post the _complete_ code. And take it easy with whitespace,
will you?

Victor
Jul 19 '05 #2

Hi Victor

Thanks for your trail, here am sending you the VarbindList class
definition.

_______________

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
hoe 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 header files of both VarbindList and NameValuePair on
the top.Help ASAP
--
Posted via http://dbforums.com
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: AnuSree | last post by:
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:
2
by: Dave | last post by:
I'm crossposting this to both comp.lang.c++ and gnu.gcc because I'm not sure if this is correct behavior or not, and I'm using the gcc STL and compiler. When calling vector<int>::push_back(0),...
2
by: franklini | last post by:
hello people i. can anybody help me, i dont know what is wrong with this class. it has something to do with the me trying to override the input output stream. if i dont override it, it works fine....
3
by: utab | last post by:
Dear all, I tried to solve the occurence problem: to find the distinct occurences of a word in an input. I know that I could use map and other STD lib functions. I tried to do it the hard way. I...
2
by: toton | last post by:
Hi, I am trying to use boost::range with one of my own container class, and having some problem. I am missing some usage of range. Can anyone suggest a proper way for it ? To show the problem...
3
by: mast2as | last post by:
sorry i am too sure how to write a more explicit subject but this code doesn't compile for the type string and I am not sure why (and I am not sure either how to describe the problem but by looking...
1
by: shark | last post by:
Hi, all. This time I met a problem in "inserter" functional. My program is like the following: /////////////////////////////////////////////////////////////////////////// #include <iostream>...
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
2
by: Man4ish | last post by:
I have created Graph object without vertex and edge property.It is working fine. #include <boost/config.hpp> #include <iostream> #include <vector> #include <string> #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.