Hello!
I would like to be able to serialize my custom vector class to a QDataStream, and for some reason that I don't understand, my operator overloading doesn't work.
Here is the relevant part of my vector class:
#include <QDataStream>
template <int N=3>
class NVec
{
double v[N];
public:
NVec() {memset(v, 0, N*sizeof(double));}
};
template <int N>
QDataStream& operator<<(QDataStream& out, const NVec<N> &o)
{
for (int i = 0; i < N; i++)
out << o[i];
return out;
}
template <int N>
QDataStream& operator>>(QDataStream& in, const NVec<N> &o)
{
for (int i = 0; i < N; i++)
in >> o[i];
return in;
}
#include <QDataStream>
template <int N=3>
class NVec
{
double v[N];
public:
NVec() {memset(v, 0, N*sizeof(double));}
};
template <int N>
QDataStream& operator<<(QDataStream& out, const NVec<N> &o)
{
for (int i = 0; i < N; i++)
out << o[i];
return out;
}
template <int N>
QDataStream& operator>>(QDataStream& in, const NVec<N> &o)
{
for (int i = 0; i < N; i++)
in >> o[i];
return in;
}
To copy to clipboard, switch view to plain text mode
The compiler complains with
no match for 'operator>>' (operand types are 'QDataStream' and 'double')
even though I am certain that I have used QDataStream with doubles before. It is also strange that only the read operator fails, but not the write operator.
Can anyone please point out where I went wrong?
Thanks
Cruz
Bookmarks