S
Stefan Slapeta
Hi,
I've found some strange behaviour with some smart pointers. Consider this
little sample:
// **********************************************************
struct MyStruct {};
template <typename T>
struct Wrapper
{
explicit Wrapper(T* p) : m_ptr(p) {}
private:
T *m_ptr;
friend bool operator < (const Wrapper <T>& left, const Wrapper <T>&
right);
};
template <class T>
inline bool operator < (const Wrapper <T>& left, const Wrapper <T>& right)
{
return *(left.m_ptr) < *(right.m_ptr); // forward!
}
inline bool operator < (const MyStruct& left, const MyStruct &right)
{ return true; }
int main()
{
MyStruct a, b;
Wrapper<MyStruct> wa(&a), wb(&b);
wa < wb;
}
// **********************************************************
There is a wrapper class (that could be a smart pointer) which forwards
operator < to its wrapped class.
This code is compiled without problems but the linker complains about an
unresolved external, which is very strange:
error LNK2019: unresolved external symbol "bool __cdecl operator<(struct
Wrapper<struct MyStruct> const &,struct Wrapper<struct MyStruct> const &)"
(??M@YA_NABU?$Wrapper@UMyStruct@@@@0@Z) referenced in function _main
Regards, Stefan
I've found some strange behaviour with some smart pointers. Consider this
little sample:
// **********************************************************
struct MyStruct {};
template <typename T>
struct Wrapper
{
explicit Wrapper(T* p) : m_ptr(p) {}
private:
T *m_ptr;
friend bool operator < (const Wrapper <T>& left, const Wrapper <T>&
right);
};
template <class T>
inline bool operator < (const Wrapper <T>& left, const Wrapper <T>& right)
{
return *(left.m_ptr) < *(right.m_ptr); // forward!
}
inline bool operator < (const MyStruct& left, const MyStruct &right)
{ return true; }
int main()
{
MyStruct a, b;
Wrapper<MyStruct> wa(&a), wb(&b);
wa < wb;
}
// **********************************************************
There is a wrapper class (that could be a smart pointer) which forwards
operator < to its wrapped class.
This code is compiled without problems but the linker complains about an
unresolved external, which is very strange:
error LNK2019: unresolved external symbol "bool __cdecl operator<(struct
Wrapper<struct MyStruct> const &,struct Wrapper<struct MyStruct> const &)"
(??M@YA_NABU?$Wrapper@UMyStruct@@@@0@Z) referenced in function _main
Regards, Stefan