Thread: How keep constructor from being called till "ready"?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    In order to do this (and I'm not sure why you would), you would have to hold that variable as a pointer, and then allocate an object with "new" at the proper moment. Now that you'd used new, you need to use delete at some point, or use a smart pointer. Why are you trying to do this?

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    184
    Quote Originally Posted by brewbuck View Post
    In order to do this (and I'm not sure why you would), you would have to hold that variable as a pointer, and then allocate an object with "new" at the proper moment. Now that you'd used new, you need to use delete at some point, or use a smart pointer. Why are you trying to do this?
    OK, I really wanted to do it without a pointer. Is there no other way?

    The reason I'm doing it is that this class is an interface into data stored in TLS and if it's constructed with an argument, it saves that to TLS otherwise it fchecks if the data is in the TLS and if not it creates the data from a configuration and stores that.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by 6tr6tr View Post
    OK, I really wanted to do it without a pointer. Is there no other way?

    The reason I'm doing it is that this class is an interface into data stored in TLS and if it's constructed with an argument, it saves that to TLS otherwise it fchecks if the data is in the TLS and if not it creates the data from a configuration and stores that.
    Perhaps a class is not really the right solution here. Perhaps just create a global SetOwner() function which does this "stuff" depending on whether it was passed an argument or not. A class really, really wants to construct all of its members, so doing goofy stuff to try to avoid that behavior is probably a sign that a class is not the right design.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read characters till white space
    By ashok449 in forum C Programming
    Replies: 2
    Last Post: 03-08-2008, 03:56 AM
  2. this returned destructor called...
    By Carlos in forum C++ Programming
    Replies: 54
    Last Post: 09-30-2003, 03:31 AM
  3. config files for exe's that are called with a batch
    By stormbringer in forum Windows Programming
    Replies: 2
    Last Post: 06-24-2003, 09:05 AM
  4. Finding the line and file in which a function was called
    By roktsyntst in forum C++ Programming
    Replies: 2
    Last Post: 04-20-2003, 10:30 AM
  5. What is this program called?
    By DarkViper in forum Linux Programming
    Replies: 6
    Last Post: 12-05-2002, 01:27 PM