c++ - Static Variables in Overloaded Functions -


I have a function that does the following:

  • When the function is called Is done and a true bool value is set to, it sets a constant force value for the right
  • The function is called string and is crossed, if the static bool value is set to true , It will do something with that string

This is my concern - is there a steady variable between two overloaded functions Will it remain? If not, then I could just build a different function that was designed to keep track of the Bull value, but I try to keep things simple. No, it creates two separate stable variables - one for each function is the name of any C ++ function named after its explicit name and its parameter types. , And the name of the stable (at least) strikes it, instead of adding another function, you may want to consider stabilizing the variable in relation to the class that maintains the function, although this is exactly the same behavior Does not give it, or anyone Anonymous namespace puts it in:

  namespace {int myvar = 0; } Int f (bool b) {return myvar; } Int f (const string & amp; s) {myvar return; }  

To create members of a square:

  // class A {public: static id (bool) {return myvar; } Fixed Intel F (Constant & amp;) {return myvar; Private: Static Int Mewer; }; // a.cpp int A :: myvar = 0; // main.cpp # include & lt; Iostream & gt; # Include & lt; A.h> Int main () {std :: cout & lt; & Lt; A: F (wrong) & lt; & Lt; A :: F (string ("FOOB"))  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -