Re: subclassing question
- From: "robbio" <roberto674@xxxxxxxxxxx>
- Date: Sat, 1 Nov 2008 11:25:35 +0100
I have a c++ template class derived from another template class. Call-----------------------------------------------------------------------
them ClassB and ClassA, respectively. I would like to be able to use
all of the ClassA functions in an instance of ClassB, but extend some
of them as in the code below.
Unfortunately, I get a compiler error:
error C2660: 'ClassB< T >::SomeFunction' : function does not take 3
arguments
When can I do to get the functionality I want?
Thanks,
PaulH
template< typename T >
class ClassA
{
void SomeFunction( int A, int B, bool C )
{
// ...
}
// ...
}
template< typename T >
class ClassB : public ClassA< T >
{
void SomeFunction( int A, int B )
{
// ...
}
// ...
}
void main()
{
ClassB< int > instance;
instance.SomeFunction( 1, 2 ); // works fine
instance.SomeFunction( 1, 2, 3 ); // error!
}
Hi PaulH,
first of all, you cannot call what you have done as Subclassing, but it is
called Derivation, the class B derive from class A.
Secondly, in your class example is missing some important C++ key "Private"
or "Public" or "Protected" you chose or you had to chosen.
So, if your example is right, then by default A::SomeFunction(...) is
private to class A, and class B never see the A::Some Function(...)
as its method also. So the compiler is right showing you the error. If you
want to use the A::SomeFunction(...) in an instance of class B
, as in your exmplae you mean to be (B::SomeFunction(int a, int b, int c)),
you have to declare the A:SomeFunction(...) in class A as Protected method.
roberto
.
- Follow-Ups:
- Re: subclassing question
- From: Alex Blekhman
- Re: subclassing question
- References:
- subclassing question
- From: PaulH
- subclassing question
- Prev by Date: Re: subclassing question
- Next by Date: Re: subclassing question
- Previous by thread: Re: subclassing question
- Next by thread: Re: subclassing question
- Index(es):
Relevant Pages
|