Hi Xcode-users
I'm having an issue compiling some source code that I've ported over from Windows. It's one of those things where I've spent a long time staring at it and can't work out why it doesn't like it.
I'm building on an iMac, Xcode version 3.2.5, GNU 4.2.1.
Here is the code: #include <string>
template<class T> class CompoundObject { public: CompoundObject(int obj1, T* obj2) : m_object1(obj1), m_object2(obj2) {}
int m_object1; T* m_object2; };
class Streamer { public: Streamer() {} ~Streamer() {}
template<class T> Streamer& operator>>(CompoundObject<T>& c) { printf("Obj1 = %d\n", c.m_object1); return *this; } };
template<class T> inline CompoundObject<T> MakeCompoundObject(int obj1, T* obj2) { return CompoundObject<T>(obj1, obj2); }
int _tmain(int argc, _TCHAR* argv[]) { Streamer s; std::string object("Hello"); s >> MakeCompoundObject(1, &object); <== ERROR return 0; }
The error returned is: /Volumes/Development/TemplateSample/TemplateSample.cpp: In function 'int _tmain(int, char**)': /Volumes/Development/TemplateSample/TemplateSample.cpp:47: error: no match for 'operator>>' in 's >> MakeCompoundObject [with T = std::string](1, (& object))' /Volumes/Development/TemplateSample/TemplateSample.cpp:29: note: candidates are: Streamer& Streamer::operator>>(CompoundObject<T>&) [with T = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]
The weird thing about the error is it identifies the correct candidate function, but is then refusing to use it. If I create a temporary variable to hold the result of MakeCompoundObject, and then call "s >> temporary", it compiles fine but that is rather spoiling the brevity of some of our code.
Any ideas?
Thanks in advance Damian
|