Re: operator==
A couple of important questions. Does your Base class contain data
members? Does at least one derived class contain data members? Are there
any derived classes of derived classes?
Ein moment I think I'm almost there, but just a simple question
I get this error:
/root/pad_mobility/include/Serializable.hpp:16: undefined reference to `vtable for Serializable'
/root/pad_mobility/include/Serializable.hpp:14: undefined reference to `vtable for Serializable'
mobpad-test.o:(.rodata._ZTV10RingBufferIP6PacketE[vtable for RingBuffer<Packet*>]+0x18): undefined reference to `Serializable::operator==(Serializable const&) const'
mobpad-test.o:(.rodata._ZTV9BasicTypeIiE[vtable for
BasicType<int>]+0x18): undefined reference to
`Serializable::operator==(Serializable const&) const'
but only for two classes, which are templated and all defined in the
header file.
So the question is if that could be the problem or maybe also the other
classes would not work?
I also moved the operator== out of the declaration now but it's the
same...
For example here is one of the two classes that generates the error:
template<class T>
class BasicType : public Serializable
{
private:
T value;
public:
BasicType() {}
BasicType(T _value) : value(_value) {}
BasicType& operator=(const T &rhs) {
// Check for self-assignment!
if (this == &rhs)
return *this;
value = rhs;
return *this;
}
Stream toStream() const {
return Stream::fromBasic<T>(value);
}
static BasicType<T> parseStream(Stream& raw) {
BasicType<T> res;
res.value = raw.toBasic<T>();
return res;
}
bool operator==(const BasicType<T>&) const;
T getValue() const { return value; }
// see here about why we need the double template declaration
// http://stackoverflow.com/questions/4039817/friend-declaration-declares-a-non-template-function
template<typename X>
friend std::ostream& operator<<(std::ostream&, const BasicType<X>&);
};
template<typename T>
std::ostream& operator<<(std::ostream& s, const BasicType<T>& basic)
{
s << basic.value;
return s;
}
template<typename T>
bool BasicType<T>::operator==(const BasicType<T>& other) const
{
return (value == other.value);
}