I appolagise for the slightly ambiguous title, I didn't know what to call it.
I want to create a way to define interfaces without having to also write the class declaration that implements it.
I have the class members, and the interface defined, but I am not sure how (if possible) to make it generate the implentation class declaration as well.
For anyone who doesn't know __interface makes all the functions within it automatically public and pure virtual.
Idealy this is how I would like to write the interfaces:
BeginMembers( ITest )
int m_nTest;
EndMembers( ITest )
BeginInterface( ITest, CTest ) // not sure if these will be the actuall paramaters
void TestFunc( void );
EndInterface( ITest, CTest )
void CTest::TestFunc( void )
{
printf( "%d\n", m_nTest );
}
Which would generate code like this:
class ITest_members
{
protected:
int m_nTest;
};
__interface ITest // I'm aware that this is not portable.
{
public:
void TestFunc( void );
};
class CTest : public ITest_members, public ITest
{
public:
void TestFunc( void );
};
Right now this is the code I have:
#define BeginMembers( iName ) class iName##_members { protected:
#define EndMembers( iName ) };
#define BeginInterface( iName ) __interface iName##_interface {
#define EndInterface( iName ) \
class iName : public iName##_interface, public iName##_members \
{ \
public: \
~iName( void ) { } \
};
I'm stuck on how to get it to generate the CTest class declaration, any ideas would be greatly appreciated.
The reason that I'm doing this is that I'm lazy and don't want to have to write the CTest class that is exactly the same as the interface class.