| |

VerySource

 Forgot password?
 Register
Search
View: 784|Reply: 7

A question about c ++ inheritance

[Copy link]

3

Threads

9

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-1-7 11:00:01
| Show all posts |Read mode
In the main function, if the object defined by the derived class cannot directly access the member function of the base class, what kind of inheritance should be used? ? Or what more tricks? Please enlighten me!
Reply

Use magic Report

0

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Australia

Post time: 2020-1-7 14:18:01
| Show all posts
Functions that are not allowed to access are declared private in the base class.
Reply

Use magic Report

0

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Australia

Post time: 2020-1-7 15:00:01
| Show all posts
Or use private inheritance, but this way, the behavior can not see the connection between the derived class and the base class. It's better to use a combination.
Reply

Use magic Report

0

Threads

49

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-1-8 02:36:01
| Show all posts
Functions that use private inheritance and are not allowed to access are declared private in the base class. Remember to do this.
Reply

Use magic Report

0

Threads

36

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-8 08:09:01
| Show all posts
private inheritance
If you want to make the inherited class accessible without external access, use protected
If you want both, use public
Reply

Use magic Report

0

Threads

49

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-1-8 08:54:01
| Show all posts
Oh, I seem to remember it wrong, haha
Reply

Use magic Report

1

Threads

19

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-8 09:45:01
| Show all posts
Define base class member functions as private
Reply

Use magic Report

3

Threads

9

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

 Author| Post time: 2020-1-10 18:45:01
| Show all posts
Thank you everyone!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list