Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Possible Conflict?

Reply
Thread Tools

Possible Conflict?

 
 
Trevor M. Lango
Guest
Posts: n/a
 
      02-04-2004
Could the following code produce errors / unpredictable results?

static someClass *someVar = new someClass( );


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      02-04-2004
"Trevor M. Lango" <(E-Mail Removed)> wrote...
> Could the following code produce errors / unpredictable results?
>
> static someClass *someVar = new someClass( );
>
>


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


 
Reply With Quote
 
 
 
 
Bob Hairgrove
Guest
Posts: n/a
 
      02-04-2004
On Wed, 04 Feb 2004 19:56:48 GMT, "Trevor M. Lango"
<(E-Mail Removed)> wrote:

>Could the following code produce errors / unpredictable results?
>
> static someClass *someVar = new someClass( );
>


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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Jonathan Turkanis
Guest
Posts: n/a
 
      02-04-2004

"Trevor M. Lango" <(E-Mail Removed)> wrote in message
news:48cUb.21507$e%(E-Mail Removed) m...
> Could the following code produce errors / unpredictable results?
>
> static someClass *someVar = new someClass( );
>


Yes:

struct someClass {
someClass() {
reinterpret_cast< std::vector<int>*
>(this)->assign(1000000000, 0);

}
};

Jonathan.


 
Reply With Quote
 
David Fisher
Guest
Posts: n/a
 
      02-05-2004
"Trevor M. Lango" <(E-Mail Removed)> wrote:

> Could the following code produce errors / unpredictable results?
>
> static someClass *someVar = new someClass( );


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


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
efficient data loading with Python, is that possible possible? igor.tatarinov@gmail.com Python 10 12-14-2007 04:44 PM
is it possible to possible to create an iterator from a callback interace? aninnymouse@gmail.com C Programming 4 02-21-2006 02:10 PM
XML + XSD: Is it possible to get all possible Values for an Element? Markus Java 1 11-22-2005 02:51 PM
Possible to connect 2 computers via USB? Michael Giroux Wireless Networking 2 09-02-2004 03:27 AM
Possible domain related wireless problem =?Utf-8?B?QWxpIEQ=?= Wireless Networking 0 08-10-2004 01:59 AM



Advertisments