My interface declarations usually (always?) follow the same scheme. Here's an example:
class Output
{
public:
virtual ~Output() { }
virtual void write( const std::vector<char> &data ) = 0;
protected:
Output() { }
private:
Output( const Output &rhs ); // intentionally not implemented
void operator=( const Output &other ); // intentionally not implemented
};
The boilerplate is always the same: public virtual destructor, a few pure virtual methods which make up the actual interface. protected default ctor, disabled copy construction and copy assignment. I started using two little helper macros which can be used to simplify the above to
ABSTRACT_BASECLASS_BEGIN(Output)
virtual void write( const std::vector<char> &data ) = 0;
ABSTRACT_BASECLASS_END(Output)
Unfortunately, I didn't find a nice way to do this with just a single macro. Even better, I'd like to avoid macros entirely. However, the only thing which came to my mind was a code generator, which is a bit overkill for me.
What is the simplest way to declare an interface in C++ - directly in the language. Preprocessor use is acceptable, but I'd like to avoid external code generators.