Re: subclassing question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: subclassing question
    ... them ClassB and ClassA, respectively. ...     void SomeFunction(int A, int B, bool C) ... ClassA typically requires you to open a handle to a resource and then ...
    (microsoft.public.vc.language)
  • Re: subclassing question
    ... them ClassB and ClassA, respectively. ... all of the ClassA functions in an instance of ClassB, ... void SomeFunction(int A, int B, bool C) ...
    (microsoft.public.vc.language)
  • Re: subclassing question
    ... them ClassB and ClassA, respectively. ... void SomeFunction(int A, int B, bool C) ...
    (microsoft.public.vc.language)
  • Re: subclassing question
    ... them ClassB and ClassA, respectively. ...    void SomeFunction(int A, int B, bool C) ...
    (microsoft.public.vc.language)
  • Re: Some thoughts about OO programming
    ... compilers, that try to make code as machine friendly as possible (with ... Alpha designs a class named ClassA. ... Company Beta wants to write a class ClassB. ... libraries are loaded by the dynamic linker of the OS and it ...
    (comp.programming)