开发者

ArrayList C++ problem

I've found an arraylist class on the internet, on http://code.google.com/p/arraylist/downloads/detail?name=arraylist-v1.zip .

On windows using MS Visual C++ it compiles fine, under OS X with GCC I get tons of errors. Here's the error output:

"/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[](in开发者_运维百科t) 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)

Is there some kind of VC++ compatibility flag, or even better, could you provide one sample correction, so I can correct them all?

Thanks!

Yvan


My guess is that you're compiling the cpp files even though arraylist.h includes them. Let's take a look at the code…

// arraylist.operators.cpp

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

and then we've got

// arraylist.h

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

So, if you compile arraylist.operators.cpp, it includes arraylist.h, which includes arraylist.operators.cpp…

This class looks like a piece of shit, just use std::vector.


There is no compatibility flag. Did you look at the STL list? It's already implemented for both visual c++ and gcc and may do what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜