473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

public base class

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 !!
Jul 19 '05 #1
2 2381
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?

Jul 19 '05 #2
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" <do***********@datafast.net.au> wrote in message
news:3f******@usenet.per.paradox.net.au...
"ET2 Ng" <al************@att.woo-haa.net> wrote in message
news:NN*********************@bgtnsc05-news.ops.worldnet.att.net
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::print5; // 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)

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: qazmlp | last post by:
class base { // other members public: virtual ~base() { } virtual void virtualMethod1()=0 ; virtual void virtualMethod2()=0 ; virtual void virtualMethod3()=0 ;
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
2
by: Tony Johansson | last post by:
Hello experts! My question is what advantage and disadvantage have public inheritance. The answer that I have to this is that sometimes it is an advantage to let a client have access to...
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
5
by: Earl Teigrob | last post by:
Is there a way to rename the public properties of a inherited class? I am inheriting an asp.net control (class) and am adding addtional functionality. (in this case, up to 3 borders on an...
4
by: santel | last post by:
Hi all, I have these classes public class Base { private string str; private string str1; public string MyStr; {
6
by: Ajay Martin | last post by:
Why would it be reasonable for someone to argue that it is incorrect to allow a public member inherited from a public base class to be redefined as private?
2
by: Fred | last post by:
I've got the following code: #include <iostream> class Base{ private: virtual void f(int) { std::cout << "f in Base" << std::endl; } };
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.