2

As a C programmer, I'd like to ask a question related to C++.

Suppose doSomething(), which has a static local variable, is a public method of a class in C++. And suppose we have created two instances of this class.

Now, is there only one copy of this static variable in memory, shared between the two instances? I guess this should be the case.

1
  • 3
    Yes, that is the case. Commented Feb 26, 2019 at 5:25

2 Answers 2

1

Is there only one copy of this static variable in memory, shared between the two instances?

Yes

Sign up to request clarification or add additional context in comments.

Comments

0

The lifetime of the static variable is from the time the program flow encounters the declaration to when the program terminates. It is shared by any instance of the class.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.