473,408 Members | 1,980 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,408 software developers and data experts.

protected inheritance modifier

Hello!
Suppose I have:

class B {
protected:
virtual ~B();
};

class D: public B {
public:
~D();
};
Is it a good practice to use "protected" in class B?
Jul 19 '05 #1
3 4207
Wenjie wrote:
Hello!
Suppose I have:

class B {
protected:
virtual ~B();
};

class D: public B {
public:
~D();
};
Is it a good practice to use "protected" in class B?


only if you want methods in classes that inherit B be the only methods
able to delete B.

Jul 19 '05 #2
Wenjie wrote:
Suppose I have:

class B {
protected:
virtual ~B();
};

class D: public B {
public:
~D();
};
Is it a good practice to use "protected" in class B?


Not an answer to your question, but something to keep i mind:
Making your dtor protected will keep your class from being used in 3rd-party
custom memory-mgt code which calls the dtor directly (as in,
thefoo->~foo()).

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

Jul 19 '05 #3
"stephan beal" <st*****@wanderinghorse.net> wrote...
Wenjie wrote:
Suppose I have:

class B {
protected:
virtual ~B();
};

class D: public B {
public:
~D();
};
Is it a good practice to use "protected" in class B?
Not an answer to your question, but something to keep i mind:
Making your dtor protected will keep your class from being used in

3rd-party custom memory-mgt code which calls the dtor directly (as in,
thefoo->~foo()).


.... or indirectly, anywhere, as in

{
foo afoo;
...
} // afoo::~foo() is supposed to be called here

Victor
Jul 19 '05 #4

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

Similar topics

1
by: AIK | last post by:
I have the following two classes: package birdpack; public class Bird { Bird() {} protected int nFeathers;
5
by: Christian Meier | last post by:
Hi dear programmers I looked for the difference between private and protected inheritance, but couldn't find anything. Here is my sample code: #include <iostream> using std::cout; using...
4
by: Pradeep Kumar | last post by:
/*******calc.cpp*********************/ # include <iostream.h> # include"calc.h" int calc::func(date d){ d.num = 31; return (d.num); }
2
by: Dan Cimpoiesu | last post by:
Hello What does mean when a protected modifier is apllied to a class. I want to inherit a protected class defined in another class, I saw that the microsoft programmers achieved that. But I...
3
by: steve | last post by:
Greetings, I have a question about interfaces and inheritance. We are going to create X number of classes that are going to doSomething (see below) cool with typed datarows. I optimistically...
5
by: | last post by:
hello there, what is the difference between Shared and Protected Shared? where can I read more about theses kind of variables (or whatever they are....sorry, don't know the word in eng.) ...
1
by: relient | last post by:
Hi, I just started the chapter on "Inheritance" and I'm a bit confused so I have three questions: first, here's the code: using System; using System.Collections.Generic; using System.Text; ...
13
by: Tom Baxter | last post by:
Hi everyone, Has anyone looked at section 18.1.1 of the C# spec? It indicates 'new' and 'protected' are valid modifiers on struct declarations. First, how can 'protected' be valid on a struct,...
8
by: Mayur H Chauhan | last post by:
All, For my knowledge, if I declare Class as follow, then it thows compilation error. Protected Class Book End Class Even same for...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.