What are disadvantages of using static variables like in following code:
namespace XXX
{
static int i;
class YYY
{
static m_i;
};
}
Is using static variables only in .cpp (so they are invisible to other code) file OK?
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.
Various things allowed by C++ represent choices and compromises in software design. There is nothing inherently, absolutely evil about any of them (except perhaps throw specifications, which Prof. Stroustrop deems a broken facility ;-P).
Whether this particular code is a good choice in a particular situation depends on many factors. For example:
static:In short, if you realise that namespaces and static just reduce identifier clashes, they’ve got all the other pros/cons associated with global variables….