Is it possible to declare a class destructor as private? 8 7463
On Mon, 18 Jul 2005 15:08:02 +0000 (UTC), Alfonso Morra
<sw***********@the-ring.com> did courageously avow: Is it possible to declare a class destructor as private?
Try it and see.
I would venture not though because the program would no longer be able
to call it. :-)
Ken Wilson
"Coding, coding, over the bounding main()"
Ken Wilson wrote: On Mon, 18 Jul 2005 15:08:02 +0000 (UTC), Alfonso Morra <sw***********@the-ring.com> did courageously avow:
Is it possible to declare a class destructor as private?
Try it and see.
I already did and found the answer (that's why I deleted the OP). I would venture not though because the program would no longer be able to call it. :-)
Not necessarily true. This is a nested class that must not be accesible
outside its parent contaner. The container object is declared a friend
and therefore has access to the nested classes private parts. Ken Wilson "Coding, coding, over the bounding main()"
True, but if the class/function were made a friend, it would have
access to the class's destructor.
On 18 Jul 2005 08:22:13 -0700, "titancipher" <ja***********@gmail.com>
did courageously avow: True, but if the class/function were made a friend, it would have access to the class's destructor.
Fair enough. I was thinking about making the nested class private to
the container and then the destructor could be made public.
Ken Wilson
"Coding, coding, over the bounding main()"
Ken Wilson wrote: On Mon, 18 Jul 2005 15:08:02 +0000 (UTC), Alfonso Morra <sw***********@the-ring.com> did courageously avow:
Is it possible to declare a class destructor as private? Try it and see.
There exists a well-known compiler (from a very big company) that
ignores the private-ness of destructors.
I would venture not though because the program would no longer be able to call it. :-)
Hint: friendship
"Mercator" <me********@spambob.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com Ken Wilson wrote: On Mon, 18 Jul 2005 15:08:02 +0000 (UTC), Alfonso Morra <sw***********@the-ring.com> did courageously avow:
Is it possible to declare a class destructor as private?
Try it and see.
There exists a well-known compiler (from a very big company) that ignores the private-ness of destructors.
If it is the company that I am thinking of, then I am unable to reproduce
this. In particular, the following code won't compile on versions 6.0, 7.1
and 8.0 Beta 2 (I haven't tested 7.0):
class Test
{
~Test(){}
};
int main()
{
Test t;
}
--
John Carson
John Carson wrote: If it is the company that I am thinking of, then I am unable to reproduce this. In particular, the following code won't compile on versions 6.0, 7.1 and 8.0 Beta 2 (I haven't tested 7.0):
You are right. I confused it with a problem I had some time ago using a
private operator delete.
See Scott Meyers, More effective C++, item 27.
If you want to force the creation of an object on the heap,
then you use a private destructor and provide a public
member function destroy.
class Demo {
~Demo() {} // private
public:
void destroy() const
{
delete this;
}
};
Now the following won't work:
void foo()
{
Demo d;
}
regards, Stephan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stub |
last post by:
Please answer my questions below - thanks!
1. Why "Derived constructor" is called but "Derived destructor" not in Case
1 since object B is new'ed from Derived class?
2. Why "Derived destructor"...
|
by: Christopher Benson-Manica |
last post by:
I swear, this godforsaken __fastcall qualifier that Borland came up
with is going to drive me insane! All I want is to subclass from a
class A with a destructor declared
virtual __fastcall...
|
by: lovecreatesbeauty |
last post by:
The following shortened table comes from a big company's C++ technical
document accompanied with its C++ compiler. This company's C++ compiler
was/is very popular in Windows platform programming....
|
by: Tony Johansson |
last post by:
Hello!!
Is it possible to have abstract destructor.
//Tony
|
by: __PPS__ |
last post by:
Hello everybody,
in my exam in c++ I answered that destructors may be declared private,
public or protected.
The question was: "What possible scopes (public or private) can a
destructor have?"
...
|
by: Michael |
last post by:
Hello,
I want to use an object (LowCut) within another object (SampleRateConverter)
like it is written as follows:
class SampleRateConverter
{
public:
SampleRateConverter( int...
|
by: Ben Voigt |
last post by:
I have a POD type with a private destructor. There are a whole hierarchy of
derived POD types, all meant to be freed using a public member function
Destroy in the base class. I get warning C4624....
|
by: VSP |
last post by:
Hello,
I am just implementing singleton pattern in various ways. In one
implementation I created a static member and returning that static member in
the getInstance() function. I have made...
|
by: Ramkey |
last post by:
I was asked in a test
class A{
A ~A{
cout << "A's destructor";
}
};
int main(void){
A Aobj;
Aobj.~A;
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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: 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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |