他のアプリケーションでビルドして使用するための静的ライブラリがあります。
私の静的ライブラリでは、カスタム タイプのリストを維持したいと考えています。リストについては、標準テンプレート ライブラリのリストを使用しています。リストをトラバースするために標準のイテレータを使用しています。
メインクラスにファイルを直接含めることにより、両方のクラス、つまりカスタムタイプとカスタムタイプのリストを管理するクラスをテストしました。すべてが期待どおりに機能しています。
これを静的ライブラリとしてコンパイルし、他のアプリケーションで使用したいと考えています。ライブラリをコンパイルすると、エラーなしでコンパイルされます。アプリにライブラリを含めると、「'operator==' の型が競合しています」というエラーが表示されます。
私は開発作業に Xcode 4 を使用しています。
この「MyClass」は、リストで使用されるカスタム タイプです。
class MyClass {
private:
const void* handler;
public:
MyClass(const void*, int);
MyClass(const MyClass&);
virtual ~MyClass();
void* getHandler();
friend bool operator==(const MyClass&, const MyClass&);
};
MyClass.cpp:
MyClass::MyClass(const void* subscriber)
{
handler = subscriber;
}
MyClass::MyClass(const MyClass& subscriber)
{
handler = subscriber.handler;
}
MyClass::~MyClass()
{
}
void* MyClass::getHandler()
{
return (void *)handler;
}
bool operator==(const MyClass& lhs, const MyClass& rhs)
{
if(lhs.handler == rhs.handler)
{
return true;
}
return false;
}
リストをトラバースするためのコード スニペットは次のとおりです。
static list<MyClass> dataHandlers;
void DeviceServiceListner::unsubscribeRawData(const void* handler) {
// check list of registered handlers and remove given from the list
list<MyClass>::iterator it = dataHandlers.begin();
MyClass subscriber = *it;
while(it != dataHandlers.end()) {
if (subscriber.getHandler() == handler) {
dataHandlers.remove(subscriber);
break;
}
it++;
}
}
編集: Xcode からのエラー ログは次のとおりです。
In file included from /Users/mobiplex/svn/Software/iPhone Interface Library/InterfaceLib/InterfaceLib/src/bluetooth/DataListener.cpp:10:
In file included from /Users/mobiplex/svn/Software/iPhone Interface Library/InterfaceLib/InterfaceLib/Libraries/DeviceServiceListner.h:17:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/include/c++/4.2.1/list:69:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/include/c++/4.2.1/bits/stl_list.h:1196:5: error: conflicting types for 'operator=='
operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/include/c++/4.2.1/bits/stl_list.h:265:5: note: previous definition is here
operator==(const _List_iterator<_Val>& __x,
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/include/c++/4.2.1/bits/stl_list.h:1232:5: error: conflicting types for 'operator!='
operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/include/c++/4.2.1/bits/stl_list.h:271:5: note: previous definition is here
operator!=(const _List_iterator<_Val>& __x,
^
2 errors generated.
「DataListner」は、ライブラリから「DeviceServiceListener」をインクルードしているアプリ クラスです。エラーの考えられる原因と解決方法を教えてください。
前もって感謝します。