Possible Conflict?

  • Thread starter Trevor M. Lango
  • Start date
T

Trevor M. Lango

Could the following code produce errors / unpredictable results?

static someClass *someVar = new someClass( );
 
V

Victor Bazarov

Trevor M. Lango said:
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.
 
B

Bob Hairgrove

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?
 
J

Jonathan Turkanis

Trevor M. Lango said:
Could the following code produce errors / unpredictable results?

static someClass *someVar = new someClass( );

Yes:

struct someClass {
someClass() {
reinterpret_cast said:
(this)->assign(1000000000, 0);
}
};

Jonathan.
 
D

David Fisher

Trevor M. Lango said:
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-lite/ctors.html#faq-10.11 and the next
few questions after it.

David F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top