I too would like to know.... I did notice that you can initialize it using the 'inline' keyword: inline static int counter { 0 }; This compiles.... but I have seen inconsistencies with the counter results like this. Sometimes the counter starts negatively. No idea why.
Great tutorial. Thank you! But I'm actually having troble with another thing. I'm trying to modularize my code into MVC. How to I acess a controller variable from my view cpp? The problem is that if I declare a controller class static variable outside my class declaration (as a global variable in my controller.cpp), that variable is not accessible from my view.cpp. How do I fix this? Do I have to pass variables or pointers as parametrs of class methods?
Thanks Paulo! :-) That's a great question. I don't have a tutorial on this topic yet, but for the problem you're experiencing I would suggest looking up the topic "multifile projects in C++" as some of the tutorials out there around this topic may address what you're experiencing and/or trying to ultimately do. If you split the project up across .h and .cpp files that include one another in the correct way, what you're trying to do should be possible, but it's more than I think I can explain well in a comment. One day I will make a tutorial on this topic too, but I'm not sure when.
Thanks! I will. I found a way to access the variables by declaring them in the controller.h as you suggested on this tutorial, initializing them in the controller.cpp and importing the controller.cpp in my view.cpp. But I don't know if importing a cpp file into another is a good practice, tho. I'll test it today and get back to tell you if everything works fine without any linker problems Thanks again and shoutout from Brazil!
Thanks! :-) These videos may help with those concepts: Introduction to Pointers: ua-cam.com/video/2GDiXG5RfNE/v-deo.html new and delete: ua-cam.com/video/wopESdEVJs4/v-deo.html
Thank you so much, this tutorial really really help me
You’re very welcome, I’m glad that it helped you out! :-)
Great video! but can you explain little bit why static variable can only be initialized outside of class?
I too would like to know.... I did notice that you can initialize it using the 'inline' keyword: inline static int counter { 0 }; This compiles.... but I have seen inconsistencies with the counter results like this. Sometimes the counter starts negatively. No idea why.
Great ... But could you explain why your using scope resolution (::) when accessing the total
Because total was declared to be a class variable. When that is so, in this demonstration, the scope is bound to the class, and not an instance.
Great tutorial. Thank you! But I'm actually having troble with another thing. I'm trying to modularize my code into MVC.
How to I acess a controller variable from my view cpp?
The problem is that if I declare a controller class static variable outside my class declaration (as a global variable in my controller.cpp), that variable is not accessible from my view.cpp.
How do I fix this? Do I have to pass variables or pointers as parametrs of class methods?
Thanks Paulo! :-) That's a great question. I don't have a tutorial on this topic yet, but for the problem you're experiencing I would suggest looking up the topic "multifile projects in C++" as some of the tutorials out there around this topic may address what you're experiencing and/or trying to ultimately do. If you split the project up across .h and .cpp files that include one another in the correct way, what you're trying to do should be possible, but it's more than I think I can explain well in a comment. One day I will make a tutorial on this topic too, but I'm not sure when.
Thanks! I will.
I found a way to access the variables by declaring them in the controller.h as you suggested on this tutorial, initializing them in the controller.cpp and importing the controller.cpp in my view.cpp.
But I don't know if importing a cpp file into another is a good practice, tho. I'll test it today and get back to tell you if everything works fine without any linker problems
Thanks again and shoutout from Brazil!
Sounds good! :-D
great as always, but you didnt explain the 'star' and the 'new' that you used
Thanks! :-) These videos may help with those concepts:
Introduction to Pointers: ua-cam.com/video/2GDiXG5RfNE/v-deo.html
new and delete: ua-cam.com/video/wopESdEVJs4/v-deo.html
Thank you!
You're welcome Pablo! :-D