473,327 Members | 2,055 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,327 software developers and data experts.

How to create a Leaf class in C++

If I want a class to be made as leaf class so that it cannot be inherited any
more. How can I do this.

I had heard that there is a keyword final, in Java which makes it as leaf
class, but dont know what is its equivalent in C++.

for example, make class C as leaf class.
Expand|Select|Wrap|Line Numbers
  1.         class A
  2.         {
  3.         };
  4.         class B: public A
  5.         {
  6.         };
  7.         class C: public B   // add something to make C as leaf
  8.         {
  9.         };
  10.         class D: public C // this should give error
  11.         {
  12.         };
  13.  
Regards,
Girish.
Jun 12 '07 #1
6 5256
Why u want o protect your class from being inherit ? Software reuse is a important concept in modern programming environment and save us a lot of time.

Reconsider your class design, if you want to do so.
Jun 12 '07 #2
Declare the class constructors as private. I hope this help others.
Jun 12 '07 #3
Why u want o protect your class from being inherit ? Software reuse is a important concept in modern programming environment and save us a lot of time.

Reconsider your class design, if you want to do so.
The Reason of protecting is if we are giving closed source product
to a company (ofcourse not free of cost)
with shared objects and even prototypes of functions without giving
the implimentation part then, as a security perspective it is needed
make the leaf classes in our application as final classes so that
nobody else can inherit the same.

Did you get what I mean ?????????????
Jun 12 '07 #4
gpraghuram
1,275 Expert 1GB
HI,
I think you can make the last class singleton class
Expand|Select|Wrap|Line Numbers
  1. class A
  2.         {
  3.         };
  4.         class B: public A
  5.         {
  6.         };
  7.         class C: public B   // add something to make C as leaf
  8.         {
  9. //Make this as singleton class
  10.       private:
  11.         C()
  12.         {}
  13.        ~C(){}
  14. public:
  15.    static C& instance(int x=0,int y=0) 
  16.    {
  17.     static C singleton;
  18.     return singleton;
  19.   }
  20.         };
  21.         class D: public C // this should give error
  22.         {
  23. //If u make C as singleton hen this will surely give error.
  24.         };
  25.  
Post whether this is what u expected.?

Raghuram
Jun 12 '07 #5
HI,
I think you can make the last class singleton class
Expand|Select|Wrap|Line Numbers
  1. class A
  2.         {
  3.         };
  4.         class B: public A
  5.         {
  6.         };
  7.         class C: public B   // add something to make C as leaf
  8.         {
  9. //Make this as singleton class
  10.       private:
  11.         C()
  12.         {}
  13.        ~C(){}
  14. public:
  15.    static C& instance(int x=0,int y=0) 
  16.    {
  17.     static C singleton;
  18.     return singleton;
  19.   }
  20.         };
  21.         class D: public C // this should give error
  22.         {
  23. //If u make C as singleton hen this will surely give error.
  24.         };
  25.  
Post whether this is what u expected.?

Raghuram
Why did you make this "singleton" instance as static and more over
the "singleton" which is returned is not a pointer type, then it calls copy
constructor to assign to caller and more over caller cannot be instantiated
since the constructor is private.
Can you just show me that 3 to 4 lines of code in main for creating instance
of class C.

More over I may wish to have multiple objects for C not just
one object.

Regards,
Girish.
Jun 12 '07 #6
weaknessforcats
9,208 Expert Mod 8TB
This problem:
The Reason of protecting is if we are giving closed source product
to a company (ofcourse not free of cost)
with shared objects and even prototypes of functions without giving
the implimentation part then, as a security perspective it is needed
make the leaf classes in our application as final classes so that
nobody else can inherit the same.
is not solved by making class C final.

It is solved by not exposing the class C definition to your customers. The header you use to distrubute your product should have only a class C pointer.

The actual code should be in library form. Customers never get source.

Your docset would define what methods you could call using a class C pointer.
Jun 12 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sara | last post by:
I am trying to find the average number of products of the set that is on rows...dynamically. For example, if I had states on rows and was looking at the average number of products, I would see...
7
by: Wolfgang Kreuzer | last post by:
Hello all, I have two tables - Projects and ProjectStruct Table Projects contains master records of the projects, ProjectStruct allows to define a project herarchie and contains the fields...
3
by: sumi | last post by:
How do i create a dir using python.........
2
by: bobby_b_ | last post by:
I have a table where fields 1 and 2 make up the primary key. Because of this, I have a unique composite index on fields 1 and 2 (as required by DB2). Now my question is: Fields 1 and 2 are also...
0
by: Marv | last post by:
Is it possible to print the path of all leaf nodes of an XML using XML::Simple This is the kind of output text that i'm trying to print (not the leaf node values but the path to reach them) c:\>...
1
by: mazdotnet | last post by:
Hi, I'm using the asp:TreeView component of asp.net 2.0 and my tree is structure is Root -- Parent 1 --------- Leaf 1 --------- Leaf 2
3
by: Uriah Piddle | last post by:
Hi Gang, I have a SiteMapPath, bound to a Site Map, that traces a hierarchy down to an 'Article' leaf node. But the Article page shows one of many individual articles depending on which article...
4
by: daniel.bron | last post by:
Hello, Given a XML document, an XPath to a leaf node, and a string value, what is the briefest XSLT transform to change that node's value to the given string? The node is unique, unrepeated,...
3
by: dkacher | last post by:
Hi - I'm looking for a way to generate a list of the fully-qualified paths to all of the leaf nodes in an XML Schema. The reason: I have a large schema for which I'm building a transform...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.