Connecting Tech Pros Worldwide Help | Site Map

Is a private destructor allowed here?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 06:08 AM
Joost Kraaijeveld
Guest
 
Posts: n/a
Default 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



  #2  
Old July 22nd, 2005, 06:08 AM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: Is a private destructor allowed here?

"Joost Kraaijeveld" <J.Kraaijeveld@Askesis.nl> wrote...[color=blue]
> 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;
> }[/color]

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


  #3  
Old July 22nd, 2005, 06:08 AM
Jonathan Turkanis
Guest
 
Posts: n/a
Default Re: Is a private destructor allowed here?

"Joost Kraaijeveld" <J.Kraaijeveld@Askesis.nl> wrote in message
news:TfcUb.35226$po3.30994@amsnews03.chello.com...[color=blue]
> GCC 3.3.1 allows the following code, Borland C++ 6 gives an error. I[/color]
have[color=blue]
> looked in the standard but could not find the answer. Should this[/color]
code[color=blue]
> compile, given that the private destructor (and constructor but[/color]
there[color=blue]
> Borland does not give an error) is called in the public static[/color]
function:[color=blue]
>[/color]

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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.