Thank you for good tutorial. Have a question. Where is it okay to initialize static variable? Should it be initialized in header or cpp file? And another question is it considered bad practice to make static variable public?
You're welcome! And great questions too! 🙂 We shouldn't initialize the static variable in the header, this is a good thread as to why: stackoverflow.com/questions/22869788/why-should-i-not-initialize-static-variable-in-header. I've never heard that it's a bad practice to make static variables public, I think it would depend on what they are being used for.
Thank you! Private variables cannot be defined/initialized outside the class but private static variables can be initialized outside the class using ::, right?
Yes that's true, though I believe private static variables *must* be initialized outside of the class (though if you really deep drive research it you may find there is some nuance there, I think a couple types of static members can be technically be initialized in the class).
I sure as hell that i will recomend you to my friends. I wish that you could be my professor!!!!! :)
Very well explained!
Thank you for good tutorial. Have a question. Where is it okay to initialize static variable? Should it be initialized in header or cpp file? And another question is it considered bad practice to make static variable public?
You're welcome! And great questions too! 🙂 We shouldn't initialize the static variable in the header, this is a good thread as to why: stackoverflow.com/questions/22869788/why-should-i-not-initialize-static-variable-in-header. I've never heard that it's a bad practice to make static variables public, I think it would depend on what they are being used for.
@@PortfolioCourses 🙏🙏🙏
Very good explanation
Thank you very much for the positive feedback, I'm glad you enjoyed the explanation! :-)
You guys are the best !!!
Thank you Nejat! :-)
Thank you! Private variables cannot be defined/initialized outside the class but private static variables can be initialized outside the class using ::, right?
Yes that's true, though I believe private static variables *must* be initialized outside of the class (though if you really deep drive research it you may find there is some nuance there, I think a couple types of static members can be technically be initialized in the class).