C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using declaration for base class constructors

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
sdspam@front.ru
Guest





PostPosted: Sat Jul 17, 2004 10:10 am    Post subject: Using declaration for base class constructors Reply with quote



Hi!

It is often happens that I need to derive class D from B, where B has a
set of non-trivial constructors. But, in many cases, the construction
order isn't changed. Then a bulk of stupid code is written:

class B {
public:
B( int );
B( int, int );
/*...*/

virtual void goo() = 0;
/*...*/
};

class D : public B {
public:
//>> stupid code begin
D( int a ) : B( a ) {}
D( int a, int b ) : B( a, b ) {}
/*...*/
///<< stupid code end

virtual void goo() {
/*...*/
}
/*...*/
};

Moreover, some advanced techniques are broken by this issue. For
example, we cannot use class like following:

template< typename T >
class DefaultGoo : public T {
public:
virtual void goo() {
/*default code*/
}
};

It will be nice, if C++ allows us to inherit all constructors from a
base class. The hypothetical code is:

class D : public B {
public:
using B;
virtual void goo() {
/*...*/
}
/*...*/
};

template< typename T >
class DefaultGoo : public T {
public:
using T;
virtual void goo() {
/*default code*/
}
};

Obviously, there are problems with a multiple inheritance. But I hope
that a consistent solution exists.

Does anybody know how to fix easily the problem?
Does anybody know the reasons why it cannot be added in future C++?


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Francis Glassborow
Guest





PostPosted: Sat Jul 17, 2004 5:12 pm    Post subject: Re: Using declaration for base class constructors Reply with quote



In article <cd92fm$l3j (AT) odak26 (DOT) prod.google.com>, "sdspam (AT) front (DOT) ru"
<sdspam (AT) front (DOT) ru> writes
Quote:
It is often happens that I need to derive class D from B, where B has a
set of non-trivial constructors. But, in many cases, the construction
order isn't changed. Then a bulk of stupid code is written:

Yes, this is a problem (though not everyone agrees as to how big a
problem) Uniquely (AFAIK) ctors are the only members that are not
inherited in any usable sense.
Quote:

class B {
public:
B( int );
B( int, int );
/*...*/

virtual void goo() = 0;
/*...*/
};

class D : public B {
public:
//>> stupid code begin
D( int a ) : B( a ) {}
D( int a, int b ) : B( a, b ) {}
/*...*/
///<< stupid code end

virtual void goo() {
/*...*/
}
/*...*/
};

Moreover, some advanced techniques are broken by this issue. For
example, we cannot use class like following:

template< typename T
class DefaultGoo : public T {
public:
virtual void goo() {
/*default code*/
}
};

It will be nice, if C++ allows us to inherit all constructors from a
base class. The hypothetical code is:

class D : public B {
public:
using B;
virtual void goo() {
/*...*/
}
/*...*/
};

template< typename T
class DefaultGoo : public T {
public:
using T;
virtual void goo() {
/*default code*/
}
};

Obviously, there are problems with a multiple inheritance. But I hope
that a consistent solution exists.

Does anybody know how to fix easily the problem?
Does anybody know the reasons why it cannot be added in future C++?

We are looking at this, indeed one of my papers (one that only got a
lukewarm reception in Sydney) was an attempt to address the issue. There
are other proposals for the next C++ release that could also be used to
provide a simple way to inject base class ctors into a derived class. I
hope that we at least manage to come up with a way to fix this. It is a
maintenance nightmare because if the base class acquires an extra ctor
in a new release the derived classes have to fix themselves.


--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.