Possible Conflict?

Discussion in 'C++' started by Trevor M. Lango, Feb 4, 2004.

  1. Could the following code produce errors / unpredictable results?

    static someClass *someVar = new someClass( );
     
    Trevor M. Lango, Feb 4, 2004
    #1
    1. Advertising

  2. "Trevor M. Lango" <> 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.
     
    Victor Bazarov, Feb 4, 2004
    #2
    1. Advertising

  3. On Wed, 04 Feb 2004 19:56:48 GMT, "Trevor M. Lango"
    <> 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
     
    Bob Hairgrove, Feb 4, 2004
    #3
  4. "Trevor M. Lango" <> wrote in message
    news:48cUb.21507$e%...
    > 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.
     
    Jonathan Turkanis, Feb 4, 2004
    #4
  5. Trevor M. Lango

    David Fisher Guest

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

    David F
     
    David Fisher, Feb 5, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ruslan

    namespace's conflict

    Ruslan, Jan 25, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,378
    netnews.microsoft.com
    Mar 1, 2005
  2. Matt

    Session variables conflict

    Matt, Aug 13, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    762
    Michael Pearson
    Aug 14, 2003
  3. =?Utf-8?B?RGF2ZQ==?=

    Conflict with dependency on build

    =?Utf-8?B?RGF2ZQ==?=, Oct 27, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    903
    =?Utf-8?B?RGF2ZQ==?=
    Oct 27, 2004
  4. David Gildea

    Conflict between VS2003 and VS 2005

    David Gildea, Dec 1, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    684
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=
    Dec 1, 2004
  5. charles cashion

    css conflict (or html conflict)

    charles cashion, Feb 18, 2009, in forum: HTML
    Replies:
    2
    Views:
    821
    charles cashion
    Feb 18, 2009
Loading...

Share This Page