I need a function that can take a vector
of any one of float
, int
, double
or short
. It should then copy all the data in that vector
into a new vector
of char*
.
Here my attempt. This is the first time I ever had to use memcpy
so I don't know what I am doing.
#include <vector>
#include <memory>
std::vector<float> vertices = { 0.0, 0.1, 0.2, 0.3, 0.4 };
std::unique_ptr<std::vector<char*>> buffer = std::make_unique<std::vector<char*>>();
template<class Type>
void SetVertices(const std::vector<Type>& v)
{
buffer->clear();
buffer->resize(v.size() * sizeof(Type));
memcpy(buffer.get(), v, v.size() * sizeof(Type));
}
int main()
{
SetVertices(vertices);
}
Here is the error message:
error C2664: 'void *memcpy(void *,const void *,size_t)': cannot convert argument 2 from 'const std::vector<float,std::allocator>' to 'const void *'