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

Is a private destructor allowed here?

GCC 3.3.1 allows the following code, Borland C++ 6 gives an error. I have
looked in the standard but could not find the answer. Should this code
compile, given that the private destructor (and constructor but there
Borland does not give an error) is called in the public static function:

class Object
{
public:
static Object& getObject()
{
static Object o;
return o;
}
private:
Object(){}
~Object(){}
};

int main()
{
Object& o = Object::getObject();
return 0;
}

TIA

Joost
Jul 22 '05 #1
2 1916
"Joost Kraaijeveld" <J.***********@Askesis.nl> wrote...
GCC 3.3.1 allows the following code, Borland C++ 6 gives an error. I have
looked in the standard but could not find the answer. Should this code
compile, given that the private destructor (and constructor but there
Borland does not give an error) is called in the public static function:

class Object
{
public:
static Object& getObject()
{
static Object o;
return o;
}
private:
Object(){}
~Object(){}
};

int main()
{
Object& o = Object::getObject();
return 0;
}


Nothing is wrong with the code. Since 'getObject' is a member,
it has access to all members of the class, private constructors
and destructors included.

Victor
Jul 22 '05 #2
"Joost Kraaijeveld" <J.***********@Askesis.nl> wrote in message
news:Tf*******************@amsnews03.chello.com...
GCC 3.3.1 allows the following code, Borland C++ 6 gives an error. I have looked in the standard but could not find the answer. Should this code compile, given that the private destructor (and constructor but there Borland does not give an error) is called in the public static function:


When you say Borland C++ 6 do you mean C++ Builder 6 or the new
Borland C++ compiler version 6? If the later, you should report this
to Borland.

Jonathan
Jul 22 '05 #3

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

Similar topics

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: Charles Jamieson | last post by:
I declare a class class myClass{ public: ~myClass();
4
by: alkee.na | last post by:
Hey, Here's a sample code you can easily guess the result. <result 1> #include <iostream> using namespace std; class AA { public: AA() { cout<<"AA();"<<endl; }
23
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....
10
by: piboye | last post by:
Hi ! I'm a academician in china. I have been intereted in C++ lasting. In reading the C++ Primer book, i have a trouble about union. In the book ,it said that union can have constructors and...
6
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...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
7
by: Rahul | last post by:
Hi Everyone, I was trying to implement a final class and i start having the destructor of the final class as private, class A { ~A() { printf("destructor invoked\n");
23
by: Chris Gordon-Smith | last post by:
Hello All I have a base class called Action_Request, and a set of classes corresponding to different kinds of Action_Request, each of which inherits from Action_Request. Eg:- class ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
tracyyun
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...
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,...

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.