c++ - Pass vector of pointers by reference and replace a vector of void* pointers -
i have following structure:
typedef struct{ int pkttype; void* sourcepeer; void* destpeer; void* aboutpeer; int tree; std::vector<int> cogsize; //leave ? std::vector<void*> newparents; //join_rep }packet;
in addition, have class named base_peer
declared follows:
class base_peer { ... public: virtual void createmessage(int, base_peer*, base_peer*, base_peer*, int, std::vector<int>&, std::vector<base_peer*>&, packet*); ... }
and createmessage()
function defined follows:
void base_peer::createmessage(int msgtype, base_peer* msgsourcepeer, base_peer* msgdestpeer, base_peer* msgaboutpeer, int msgabouttree, std::vector<int>& msgcogsize, std::vector<base_peer*>& newparents, packet* newpacket) { newpacket->pkttype = msgtype; newpacket->sourcepeer = msgsourcepeer; newpacket->destpeer = msgdestpeer; newpacket->aboutpeer = msgaboutpeer; newpacket->tree = msgabouttree; newpacket->cogsize = msgcogsize; newpacket->newparents = newparents; }
i want createmessage
create packet structure , assign values elements. more specifically, errors happen when try assign vector std::vector<void*> newparents
vector std::vector<base_peer*>& newparents
.
i following errors eclipse:
no known conversion argument 1 'std::vector' 'const std::vector&'
std::vector<_tp, _alloc>& std::vector<_tp, _alloc>::operator=(const std::vector<_tp, _alloc>&) [with _tp = void*; _alloc = std::allocator]
no match 'operator=' in 'newpacket->packet::newparents = newparents' base_peer.cpp
i appreciate help.
you'll have copy elements on manually, or using iterators. simplest way use assign
member function of std::vector
.
newpacket->newparents.assign(newparents.begin(), newparents.end());
this works because pointer directly convertible void pointer. if converting from void pointers, need use cast, std::transform
.
Comments
Post a Comment