Connecting Tech Pros Worldwide Help | Site Map

Possible Conflict?

  #1  
Old July 22nd, 2005, 07:08 AM
Trevor M. Lango
Guest
 
Posts: n/a
Could the following code produce errors / unpredictable results?

static someClass *someVar = new someClass( );


  #2  
Old July 22nd, 2005, 07:08 AM
Victor Bazarov
Guest
 
Posts: n/a

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, 07:08 AM
Jonathan Turkanis
Guest
 
Posts: n/a

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, 07:08 AM
Bob Hairgrove
Guest
 
Posts: n/a

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, 07:09 AM
David Fisher
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: When do I get "multiple bases have instance lay-out conflict"error? Miles answers 0 September 16th, 2008 07:35 AM
Assembly Version Conflict? vb answers 0 November 17th, 2005 02:23 AM
name conflict John answers 9 October 3rd, 2005 10:05 PM
C++: inherent conflict Web Developer answers 12 July 19th, 2005 05:02 PM