Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8232943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:58:53+00:00 2026-06-07T17:58:53+00:00

Having a simple class: class A { public: A() {} void set(int value) {

  • 0

Having a simple class:

class A {
public:
  A() {}
  void set(int value) { value_ = value; }

private:
  int value_;
};

and its global instance:

A a;
  1. Is it OK to call method set on a not yet constructed object a? That can happen when for example a.set(123) is called from a constructor of another global object in another translation unit.

  2. Will the value in the object a set by calling a.set(123) remain when the non-parametric and empty constructor of A is later called for object a?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:58:54+00:00Added an answer on June 7, 2026 at 5:58 pm

    Is it ok to call method set on a not yet constructed object a?

    No. You may not call member functions for an object that has not yet begun construction.

    (Since the answer is no, your second question requires no answer.)


    If you may need to access this global instance from multiple translation units during dynamic initialization, you can use the Meyers singleton technique:

    A& global_a()
    {
        static A a;
        return a;
    }
    

    a will be initialized when global_a() is first called. Note that in a multithreaded program you may need to concern yourself with synchronization of the initialization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble getting a simple class constructor to work. // In XModule.h class
I can't get past this issue I am having. Here's a simple example: class
Basically, I have an int value, x, that is an instance variable of a
I've got a simple class called object that I'm having a problem with. Theres
Having a simple Akka HTTP server: package org.package.some import akka.actor.{IOManager, IO, Actor} import java.net.InetSocketAddress
I'm having a simple test design problem, which I would like to solve once
I am having a simple code where i want to know when does onRestoreInstanceState
I really need help on this one. I am having a simple login form
hey guys having this really simple problem but cant seem to figure out have
I'm having a very simple problem. I'm new to WordPress and I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.