P
pixelbeast
hi,
In the following code, I would like not to have to declare the
constructors in bar ( either the default or the (int a) constructor ).
When I remove them, bar has no idea of construction with an int, so I
get compile errors. I currently have to declare them for every class
inheriting foo, and it would be much nicer just with the init. Is there
a nice way of doing this? I am currently using a
macro, like CONSTRUCTOR(bar) which feels a bit squiffy to me.
Also, if I'm not pushing my luck I would like some way to make the init
pure virtual to force implementation in inheritors, without getting the
linker error for foo::init that I get when I try.
thanks,
iain
class foo
{
public:
foo() {}
foo( int a ) {init(a);}
virtual void init ( int a ) {};
};
class bar: public foo
{
public:
bar() {}
bar( int a ):foo(a) {}
virtual void init( int a ){/*etc.*/}
};
void main()
{
bar a( 1 );
bar b;
b.init( 2 );
}
In the following code, I would like not to have to declare the
constructors in bar ( either the default or the (int a) constructor ).
When I remove them, bar has no idea of construction with an int, so I
get compile errors. I currently have to declare them for every class
inheriting foo, and it would be much nicer just with the init. Is there
a nice way of doing this? I am currently using a
macro, like CONSTRUCTOR(bar) which feels a bit squiffy to me.
Also, if I'm not pushing my luck I would like some way to make the init
pure virtual to force implementation in inheritors, without getting the
linker error for foo::init that I get when I try.
thanks,
iain
class foo
{
public:
foo() {}
foo( int a ) {init(a);}
virtual void init ( int a ) {};
};
class bar: public foo
{
public:
bar() {}
bar( int a ):foo(a) {}
virtual void init( int a ){/*etc.*/}
};
void main()
{
bar a( 1 );
bar b;
b.init( 2 );
}