一个关于内存拷贝的问题
编写一个内存拷贝函数如下
template<class T>
bool copyFunction(T* dest,T* src,int size)
{
if (dest<=src||dest>=(src+size)) //dest地址为0x00137870
{
while(size--) //src地址为0x00137868 循环第一次就报错
*dest++=*src++;
return true;
}
else
{
dest+=size-1;
src+=size-1;
while(size--)
*dest--=*src--;
return true;
}
return false;
}
main:
char* t1="bbcdef";
char* t2="aooaoo";
if(copyFunction(t1,t2,strlen(t2)))
printf("%s",t1);
vs2008中运行报错,
dest地址是0x00137870
src地址是 0x00137868
错误提示为:unctions.exe 中的 0x00fc1834 处未处理的异常: 0xC0000005: 写入位置 0x00fc7870 时发生访问冲突
请教这是神马回事?