I've got this little utility class (templated) that I inherit throughout my project/classes.
The idea is that it allows for easy packing various members into and out of the class instances (for networking etc, not entirely important)
What I've got is as follows
template<typename T>
struct Packable
/**
* Packs a <class T> into a Packet (Packet << T)
* Required for chaining packet packing
*************************************************/
virtual sf::Packet& operator <<(sf::Packet& packet) = 0; // Work-horse, must be defined by child-class
friend sf::Packet& operator <<(sf::Packet& packet, const T *t)
{
// Call the actual one, but basically do nothing...
return packet << *t;
}
friend sf::Packet& operator <<(sf::Packet& packet, const T &t)
{
// Call the actual one, but basically do nothing...
return packet << &t;
}
friend sf::Packet& operator <<(sf::Packet& packet, T *t)
{
// Call the actual one, but basically do nothing...
return packet << *t;
}
friend sf::Packet& operator <<(sf::Packet& packet, T &t)
{
// Call the actual one, but basically do nothing...
return packet << &t;
}
};
What I'm trying to do, in short is make it so only one method needs to be specified/fleshed out in the child classes (denoted by the 'virtual' word).
What I want is to provide the other methods that take various forms of the class and just dereferences them as needed to use the virtual method that will exist when the classes are compiled.
Problem is that I seem to have created some infinite loops.
friend sf::Packet& operator <<(sf::Packet& packet, T &t)
{
// Call the actual one, but basically do nothing...
return packet << &t;
}
Simply calls itself over and over. How do I dereference a reference into it's object?