c++ - ArrayList C++问题

标签 c++ arrays gcc g++ arraylist

我在网上找到了一个 arraylist 类,地址是 http://code.google.com/p/arraylist/downloads/detail?name=arraylist-v1.zip .

在使用 MS Visual C++ 的 Windows 上,它编译得很好,在带有 GCC 的 OS X 下,我遇到了很多错误。这是错误输出:

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/consolerpg
mkdir -p build/Debug/GNU-MacOSX
rm -f build/Debug/GNU-MacOSX/arraylist.operators.o.d
g++ -fpermissive   -c -g -MMD -MP -MF build/Debug/GNU-MacOSX/arraylist.operators.o.d -o build/Debug/GNU-MacOSX/arraylist.operators.o arraylist.operators.cpp
arraylist.operators.cpp:86: error: redefinition of 'datatype& arraylist<datatype>::operator[](int)'
arraylist.operators.cpp:86: error: 'datatype& arraylist<datatype>::operator[](int)' previously declared here
arraylist.operators.cpp:100: error: redefinition of 'const datatype& arraylist<datatype>::operator[](int) const'
arraylist.operators.cpp:100: error: 'const datatype& arraylist<datatype>::operator[](int) const' previously declared here
arraylist.operators.cpp:128: error: redefinition of 'const arraylist<datatype>& arraylist<datatype>::operator=(const arraylist<datatype>&)'
arraylist.operators.cpp:128: error: 'const arraylist<datatype>& arraylist<datatype>::operator=(const arraylist<datatype>&)' previously declared here
arraylist.operators.cpp:157: error: redefinition of 'arraylist<datatype> arraylist<datatype>::operator+(const arraylist<datatype>&)'
arraylist.operators.cpp:157: error: 'arraylist<datatype> arraylist<datatype>::operator+(const arraylist<datatype>&)' previously declared here
arraylist.operators.cpp:186: error: redefinition of 'const arraylist<datatype>& arraylist<datatype>::operator+=(const arraylist<datatype>&)'
arraylist.operators.cpp:186: error: 'const arraylist<datatype>& arraylist<datatype>::operator+=(const arraylist<datatype>&)' previously declared here
arraylist.operators.cpp:201: error: redefinition of 'arraylist<datatype> arraylist<datatype>::operator-(const datatype&)'
arraylist.operators.cpp:201: error: 'arraylist<datatype> arraylist<datatype>::operator-(const datatype&)' previously declared here
arraylist.operators.cpp:223: error: redefinition of 'const arraylist<datatype>& arraylist<datatype>::operator-=(const datatype&)'
arraylist.operators.cpp:223: error: 'const arraylist<datatype>& arraylist<datatype>::operator-=(const datatype&)' previously declared here
arraylist.operators.cpp:256: error: redefinition of 'arraylist<datatype> arraylist<datatype>::operator*(const int&)'
arraylist.operators.cpp:256: error: 'arraylist<datatype> arraylist<datatype>::operator*(const int&)' previously declared here
arraylist.operators.cpp:280: error: redefinition of 'const arraylist<datatype>& arraylist<datatype>::operator*=(const int&)'
arraylist.operators.cpp:280: error: 'const arraylist<datatype>& arraylist<datatype>::operator*=(const int&)' previously declared here
arraylist.operators.cpp:322: error: redefinition of 'arraylist<datatype> arraylist<datatype>::operator/(const int&)'
arraylist.operators.cpp:322: error: 'arraylist<datatype> arraylist<datatype>::operator/(const int&)' previously declared here
arraylist.operators.cpp:347: error: redefinition of 'const arraylist<datatype>& arraylist<datatype>::operator/=(const int&)'
arraylist.operators.cpp:347: error: 'const arraylist<datatype>& arraylist<datatype>::operator/=(const int&)' previously declared here
arraylist.operators.cpp:367: error: redefinition of 'bool arraylist<datatype>::operator==(const arraylist<datatype>&)'
arraylist.operators.cpp:367: error: 'bool arraylist<datatype>::operator==(const arraylist<datatype>&)' previously declared here
arraylist.operators.cpp:394: error: redefinition of 'bool arraylist<datatype>::operator!=(const arraylist<datatype>&)'
arraylist.operators.cpp:394: error: 'bool arraylist<datatype>::operator!=(const arraylist<datatype>&)' previously declared here
arraylist.operators.cpp:418: error: redefinition of 'bool arraylist<datatype>::operator>(const arraylist<datatype>&)'
arraylist.operators.cpp:418: error: 'bool arraylist<datatype>::operator>(const arraylist<datatype>&)' previously declared here
arraylist.operators.cpp:425: error: redefinition of 'bool arraylist<datatype>::operator<(const arraylist<datatype>&)'
arraylist.operators.cpp:425: error: 'bool arraylist<datatype>::operator<(const arraylist<datatype>&)' previously declared here
arraylist.operators.cpp:432: error: redefinition of 'bool arraylist<datatype>::operator>=(const arraylist<datatype>&)'
arraylist.operators.cpp:432: error: 'bool arraylist<datatype>::operator>=(const arraylist<datatype>&)' previously declared here
arraylist.operators.cpp:438: error: redefinition of 'bool arraylist<datatype>::operator<=(const arraylist<datatype>&)'
arraylist.operators.cpp:438: error: 'bool arraylist<datatype>::operator<=(const arraylist<datatype>&)' previously declared here
make[2]: *** [build/Debug/GNU-MacOSX/arraylist.operators.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 427ms)

是否有某种 VC++ 兼容性标志,甚至更好,您能否提供一个样本更正,以便我可以全部更正?

谢谢!

伊万

最佳答案

我的猜测是您正在编译 cpp 文件,即使 arraylist.h 包含它们。让我们看一下代码……

// arraylist.operators.cpp

#ifndef __arraylist_CLASS__
#include "arraylist.h"
#endif

然后我们有

// arraylist.h

#include "arraylist.cpp"
#include "arraylist.operators.cpp"

因此,如果您编译 arraylist.operators.cpp,它会包含 arraylist.h,其中包含 arraylist.operators.cpp ...

这个类看起来像一坨屎,就用std::vector吧。

关于c++ - ArrayList C++问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4126094/

相关文章:

c++ - QWidget 不显示 QLabel

java - 在这种情况下可以替代 Java ByteBuffer 吗?

bash - LIBTOOL 尝试编译 GMP 时失败

C - 在 while 循环中直接写入数组,同时使用 recv 接收数据

javascript - 对 javascript 上的数组感到困惑

mysql - 将 MySQL 与不同的 glibc 链接

C++ 函数到指针的隐式转换 : which compiler is right? Clang 和 GCC 不同意

c++ - C++11 的 Vim 语法高亮显示不会混淆其他高亮显示。例如,类/命名空间范围

c++ - 德州扑克直接检查值

c++ - 使用/O2 与/Ox 编译——哪个更快(根据经验)?