'memcpy'未在此范围内声明 [英] ‘memcpy’ was not declared in this scope
问题描述
但是我得到这个错误
'memcpy'未在此范围内声明
我试图包含memory.h(和字符串。 h)和eclipse找到函数,如果我点击开放声明,但gcc给我错误。
我该怎么办?
#include< algorithm>
#include< memory.h>
命名空间rosic
{
//等等
模板< class T>
void circularShift(T * buffer,int length,int numPositions)
{
int na = abs(numPositions);
(na>长度)
na - =长度;
T * tmp = new T [na];
if(numPositions< 0)
{
memcpy(tmp,buffer,na * sizeof(T));
memmove(buffer,& buffer [na],(length-na)* sizeof(T));
memcpy(& buffer [length-na],tmp,na * sizeof(T));
}
else if(numPositions> 0)
{
memcpy(tmp,& buffer [length-na],na * sizeof(T));
memmove(& buffer [na],buffer,(length-na)* sizeof(T));
memcpy(buffer,tmp,na * sizeof(T));
}
delete [] tmp;
}
//等等
}
每个memcpy和memmove函数都会出错。
您必须将
using namespace std;
添加到其他命名空间,或者在每个memcpy或memmove中执行此操作:
[/ b]
std :: memcpy(tmp,buffer,na * sizeof( T));
[...]
你的代码编译器不知道在哪里寻找该函数的定义。如果你使用命名空间,它知道在哪里找到函数。
另外不要忘记包含memcpy函数的头文件:
#include
I'm trying to build an open source c++ library with gcc and eclipse. But I get this error ‘memcpy’ was not declared in this scope
I've try to include memory.h (and string.h) and eclipse find the function if I click "open declaration" but gcc give me the error.
How can I do?
#include <algorithm>
#include <memory.h>
namespace rosic
{
//etc etc
template <class T>
void circularShift(T *buffer, int length, int numPositions)
{
int na = abs(numPositions);
while( na > length )
na -=length;
T *tmp = new T[na];
if( numPositions < 0 )
{
memcpy( tmp, buffer, na*sizeof(T));
memmove( buffer, &buffer[na], (length-na)*sizeof(T));
memcpy( &buffer[length-na], tmp, na*sizeof(T));
}
else if( numPositions > 0 )
{
memcpy( tmp, &buffer[length-na], na*sizeof(T));
memmove(&buffer[na], buffer, (length-na)*sizeof(T));
memcpy( buffer, tmp, na*sizeof(T));
}
delete[] tmp;
}
//etc etc
}
I get error on each memcpy and memmove function.
You have to either put
using namespace std;
to the other namespace or you do this at every memcpy or memmove:
[...]
std::memcpy( tmp, buffer, na*sizeof(T));
[...]
in your code the compiler doesnt know where to look for the definition of that function. If you use the namespace it knows where to find the function.
Furthermore dont forget to include the header for the memcpy function:
#include <cstring>
这篇关于'memcpy'未在此范围内声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!