Connecting Tech Pros Worldwide Help | Site Map

Possible Conflict?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 06:08 AM
Trevor M. Lango
Guest
 
Posts: n/a
Default Possible Conflict?

Could the following code produce errors / unpredictable results?

static someClass *someVar = new someClass( );



  #2  
Old July 22nd, 2005, 06:08 AM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: Possible Conflict?

"Trevor M. Lango" <tmlango@sbcglobal.net> wrote...[color=blue]
> Could the following code produce errors / unpredictable results?
>
> static someClass *someVar = new someClass( );
>
>[/color]

Of course. Oh, wait. Is that _all_ code there is? Then,
sorry, it doesn't compile -- 'someClass' is undefined.


  #3  
Old July 22nd, 2005, 06:08 AM
Jonathan Turkanis
Guest
 
Posts: n/a
Default Re: Possible Conflict?


"Trevor M. Lango" <tmlango@sbcglobal.net> wrote in message
news:48cUb.21507$e%.3640@newssvr25.news.prodigy.co m...[color=blue]
> Could the following code produce errors / unpredictable results?
>
> static someClass *someVar = new someClass( );
>[/color]

Yes:

struct someClass {
someClass() {
reinterpret_cast< std::vector<int>*[color=blue]
>(this)->assign(1000000000, 0);[/color]
}
};

Jonathan.


  #4  
Old July 22nd, 2005, 06:08 AM
Bob Hairgrove
Guest
 
Posts: n/a
Default Re: Possible Conflict?

On Wed, 04 Feb 2004 19:56:48 GMT, "Trevor M. Lango"
<tmlango@sbcglobal.net> wrote:
[color=blue]
>Could the following code produce errors / unpredictable results?
>
> static someClass *someVar = new someClass( );
>[/color]

I suppose it would largely depend on what the default constructor of
"someClass" does. Can it throw an exception? Does it reserve tons of
resources? Does it try to dial up your internet provider?


--
Bob Hairgrove
NoSpamPlease@Home.com
  #5  
Old July 22nd, 2005, 06:09 AM
David Fisher
Guest
 
Posts: n/a
Default Re: Possible Conflict?

"Trevor M. Lango" <tmlango@sbcglobal.net> wrote:
[color=blue]
> Could the following code produce errors / unpredictable results?
>
> static someClass *someVar = new someClass( );[/color]

If the statement is inside a function, no problem (someVar gets initialized
the first time flow of control passes this line) ...

If it is a global variable, then there are potential problems with order of
initialization:

see http://www.parashift.com/c++-faq-lit...html#faq-10.11 and the next
few questions after it.

David F


 

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,662 network members.