【发布时间】:2014-09-11 02:17:31
【问题描述】:
我正在尝试使用 gcc 和 eclipse 构建一个开源 c++ 库。 但我得到这个错误 'memcpy' 未在此范围内声明
我尝试包含 memory.h(和 string.h),如果我单击“打开声明”,eclipse 会找到该函数,但 gcc 给我错误。
我该怎么办?
#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
}
每个 memcpy 和 memmove 函数都有错误。
【问题讨论】:
-
最好将您的代码添加到帖子中-它将帮助我们帮助您
-
好吧,首先你需要提供更多关于调用 gcc 的选项的上下文以及确切的错误是什么(文件名、未编译的代码提取、复制/粘贴确切的错误)。通常
string.h与 gcc 捆绑在一起,不需要任何额外的选项,所以这里有些可疑。 -
我猜你输入错误
#include <string.h>或者在你的文件中放得太低。给我们看一些minimal example code that demonstrates the problem。 -
您是否尝试过包含
cstring并添加using namespace std;(如果这是一个cpp 文件)(en.cppreference.com/w/cpp/string/byte/memcpy)?