Connecting Tech Pros Worldwide Help | Site Map

Possible Conflict?

Trevor M. Lango
Guest
 
Posts: n/a
#1: Jul 22 '05
Could the following code produce errors / unpredictable results?

static someClass *someVar = new someClass( );


Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 22 '05

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.


Jonathan Turkanis
Guest
 
Posts: n/a
#3: Jul 22 '05

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.


Bob Hairgrove
Guest
 
Posts: n/a
#4: Jul 22 '05

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
David Fisher
Guest
 
Posts: n/a
#5: Jul 22 '05

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


Closed Thread