I am try to write a container memcpy function. However, I can't pass my container as parameter. Could anyone give me a hint?
At this moment, I create 1 more function inside class called DIn, to put information.
I try to achieve remove DIn function, and use like normal memory copy to do this.
Could somebody give me a help?
Best regards TINGMING
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
template <typename VECTOR_TYPE = char,int VECTOR_SIZE = 256>
class vector{
private:
int SIZE;
VECTOR_TYPE ARRAY[VECTOR_SIZE];
public:
vector():SIZE(VECTOR_SIZE){
}
VECTOR_TYPE& operator[](int nIndex){
assert(nIndex >= 0 && nIndex < SIZE);
return ARRAY[nIndex];
}
void DIn(VECTOR_TYPE data,int nIndex){
assert(nIndex >= 0 && nIndex < SIZE);
ARRAY[nIndex] = data;
}
int sizeof_vector(){
return SIZE;
}
};
template <typename VECTOR_TYPE,int VECTOR_SIZE1,int VECTOR_SIZE2>
void vector_memcpy(
vector <VECTOR_TYPE,VECTOR_SIZE1> *target,int tIdx,
vector <VECTOR_TYPE,VECTOR_SIZE2> source,int sIdx,
int Length)
{
int i;
for(i=0;i<Length;i++)
target->DIn(source[sIdx+i],tIdx+i);
}
int main()
{
vector <int,16> AV;
vector <int,32> BV;
int i;
for(i=0;i<16;i++)
AV[i] = i*15;
vector_memcpy(&BV,0,AV,0,16);
vector_memcpy(&BV,16,BV,0,16);
for(i=0;i<16;i++)
printf("%2d: %3d %3d %3d\n",i,AV[i],BV[i],BV[i+16]);
return 0;
}