Listing 5: A simple template class for avoiding writing the same operators and constructors

// T must inherit from NetObject
template <class T>
NetObjectT : public T
{
public:

  NetObjectT() { netClear(); }

  NetObjectT(NetObject & no)
  {
    netCopy(no);
  }

  NetObjectT(const Buffer & buf)
  {
    netRead(NetBuffer(buf));
  }

  NetObjectT<T> & operator= (NetObject &no)
  {
    netCopy(no);
    return *this;
  }

  NetObjectT<T> & operator= (const Buffer &buf)
  {
    netRead(NetBuffer(buf));
    return *this;
  }
};
— End of Listing—