class MyClass
{
public:
void method2()
{
static int i;
...
}
};
Will every instance of MyClass share one value i, or will each instance have its own copy?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
static, here, operates as in any regular function.Which means that
iisstaticwithinMyClass::method2, so there is one and only one instance of it.Having one instance of a variable per object is what instance variables are for.