从别的c++代码移植到xCode下,代码如下(代码文件是一个.hh文件):
#if defined  TOON_CHECK_BOUNDS  || defined TOON_TEST_INTERNALS
static inline void check_index(int s, int i)
{
if(i<0 || i >= s)
{
#ifdef TOON_TEST_INTERNALS
throw Internal::BadIndex();
#else
std::cerr << "Toon index out of range" << std::endl;
std::abort();
#endif
}
}
#else
///@internal
///Function used to check bounds.
///By default it does nothing. See \ref sDebug.
static inline void check_index(int, int){}
编译提示:Redefinition of 'check_index'
请问这是什么原因啊?小弟没有做过xCode,不知道这个条件编译在xCode下是否和别的平台处理方式不太一样?请xCode专家解惑~~~~

解决方案 »

  1.   


    第二个check_index的参数必须带个名字;
    贴出来的代码少了一个#endif
    没有#ifdef XXX #define XXX #endif 这个头文件预编译标志,如果用#indclude,有可能会多次包含。除了这些问题,我看不出有其他问题。没有整个项目不好判断。
      

  2.   

    代码里面不缺少#endif的,只是我没有复制完。另外给check_index的参数加了名字还是不行,报同样的错误
      

  3.   

    没有#ifdef XXX #define XXX #endif 这个头文件预编译标志,如果用#indclude,有可能会多次包含。
    另外,可以尝试着把函数改个名字,再编译看看。