Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > public base class

Reply
Thread Tools

public base class

 
 
ET2 Ng
Guest
Posts: n/a
 
      07-19-2003
Hi all,

If I recall correctly, the functions inherited from a base class are
private in the derived class.

I want to expose some of them (but not all of them) directly through my
derived class. In other words, I'm trying to avoid something like:

void PublicFunction_DerrivedClass()
{
PublicFunction_BaseClass();
}

I would appreciate any help.
--

Best wishes,
Allen

No SPAM in my email !!


 
Reply With Quote
 
 
 
 
Jacques Labuschagne
Guest
Posts: n/a
 
      07-19-2003
ET2 Ng wrote:

> Hi all,
>
> If I recall correctly, the functions inherited from a base class are
> private in the derived class.
>
> I want to expose some of them (but not all of them) directly through
> my
> derived class. In other words, I'm trying to avoid something like:
>
> void PublicFunction_DerrivedClass()
> {
> PublicFunction_BaseClass();
> }
>
> I would appreciate any help.


That all depends on what kind of inheritance you use. The default for
classes is private inheritance, and the default for structs is public
inheritance.
To use public inheritance for classes, do something like this:

class A{
public:
void foo();
};
class B: public A{
};

int main(){
B b;
b.foo();
}

--
Where am I going, and what am I doing in this handbasket?

 
Reply With Quote
 
 
 
 
ET2 Ng
Guest
Posts: n/a
 
      07-20-2003
Hi John, Jacques, all,

Aha! Exactly what I was looking for! Thanks a bunch; I knew there had
to be a way to do that!
--

Best wishes,
Allen

No SPAM in my email !!

"John Carson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "ET2 Ng" <(E-Mail Removed)-haa.net> wrote in message
> news:NNiSa.63251$(E-Mail Removed)
> > Hi all,
> >
> > If I recall correctly, the functions inherited from a base class
> > are private in the derived class.
> >

>
> As Jacques says, this depends on the type of inheritance. Private
> inheritance is the default for classes but you can specify public or
> protected.
>
> > I want to expose some of them (but not all of them) directly
> > through my derived class. In other words, I'm trying to avoid
> > something like:
> >
> > void PublicFunction_DerrivedClass()
> > {
> > PublicFunction_BaseClass();
> > }
> >
> > I would appreciate any help.
> > --
> >
> > Best wishes,
> > Allen
> >
> > No SPAM in my email !!

>
> Rather than redefine functions, you can utilise "using" declarations. Use
> private inheritance and then make a using declaration for every function
> that you want to bring from private access to public access, e.g.,
>
> class Base
> {
> public:
> void print5()
> {
> std::cout << 5 << '\n';
> }
> void print10()
> {
> std::cout << 10 << '\n';
> }
> };
>
> // private inheritance so print5 and print1 are private
> class Derived : Base
> {
> public:
> using Base:rint5; // make print5 public
> };
>
>
> int main()
> {
> Derived d;
> d.print5(); // OK
> d.print10(); // error
> return 0;
> }
>
>
> --
> John Carson
> 1. To reply to email address, remove donald
> 2. Don't reply to email address (post here instead)
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSE 4 11-15-2006 02:40 AM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola Microsoft Certification 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSD 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd realexxams@yahoo.com Microsoft Certification 0 05-10-2006 02:35 PM
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.public.dotnet.framework.windowsforms,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb Charles A. Lackman ASP .Net 1 12-08-2004 07:08 PM



Advertisments