TalkyMessage msg;
ClassWithPointers thingyContainingPointers; // inherits TalkySerialisable
msg << ofPoint(0.0f, 0.0f); // calls general (template) case)
msg << thingyContainingPointers; // calls internal serialise function defined in TalkySerialisable. i.e. we override the general case to the specific case
Is there a reliable method for determining which takes priority? general case or specific case.
i was after specialising the function
my code is like this now
class TalkyBuffer;
class TalkySerialisable {
public:
virtual void serialiseToBuffer(TalkyBuffer &b) const = 0;
virtual bool deSerialiseFromBuffer(TalkyBuffer &b) = 0;
};
class TalkyBuffer : TalkySerialisable {
public:
...
template<class T>
TalkyBuffer& operator<<(T const &object) {
if (!write(&object, sizeof(T)))
throw("Buffer overrun - insufficient space to write");
return *this;
}
...
}
///Used e.g. when putting a payload onto main buffers
template<> TalkyBuffer& TalkyBuffer::operator<<<TalkyBuffer>(TalkyBuffer const &other);
I found that gcc only allows template specialisation for functions in a namespace but not inside a class. however this works fine (apparently). recoding a lot at once so will rain back in if it doesn’t work as expected later.
“It turns out that there’s a provision in the C++ spec that explicitly disallows specializing a template class or function nested inside of a template class unless you also explicitly specialize the outer template as well. Visual Studio doesn’t enforce this rule, hence the confusion with the previous example, but g++ certainly does.”
from http://stackoverflow.com/questions/4944156/c-method-specialization-and-templates
cheers
interesting reading!
this is the link where i found out about specialising template functions aside from templated classes: http://www.gotw.ca/publications/mill17.htm