我有一个静态库来构建并在其他应用程序中使用它。
在我的静态库中,我想维护一个自定义类型的列表。对于列表,我使用标准模板库中的列表。我正在使用标准迭代器来遍历列表。
我测试了两个类,即自定义类型和一个管理自定义类型列表的类,直接在主类中包含文件。一切都按预期工作。
现在我想将它编译为一个静态库并在其他应用程序中使用它。当我编译一个库时,它编译没有错误。在将库包含到应用程序中时,我收到错误为"Conflicting types for '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&);
};
我的类.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;
}
遍历list的代码片段如下:
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”。错误的可能原因是什么,我该如何解决?
提前致谢。