Class Variables (i.e. "Static Member Variables") | C++ Tutorial

  Рет қаралды 7,840

Portfolio Courses

Portfolio Courses

Күн бұрын

Пікірлер: 13
@flaviaflash2471
@flaviaflash2471 6 ай бұрын
Great ... But could you explain why your using scope resolution (::) when accessing the total
@tong5364
@tong5364 Жыл бұрын
Thank you so much, this tutorial really really help me
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You’re very welcome, I’m glad that it helped you out! :-)
@chenchen-eo4yf
@chenchen-eo4yf 8 ай бұрын
Great video! but can you explain little bit why static variable can only be initialized outside of class?
@UnleashedCode
@UnleashedCode 27 күн бұрын
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.
@PEJOTAvix
@PEJOTAvix 2 жыл бұрын
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?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
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.
@PEJOTAvix
@PEJOTAvix 2 жыл бұрын
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!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Sounds good! :-D
@pedllz
@pedllz 2 жыл бұрын
Thank you!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome Pablo! :-D
@didiTchu
@didiTchu 2 жыл бұрын
great as always, but you didnt explain the 'star' and the 'new' that you used
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thanks! :-) These videos may help with those concepts: Introduction to Pointers: kzbin.info/www/bejne/aHinmot9areZhKc new and delete: kzbin.info/www/bejne/raDTdoaaert9qZY
Static Member Functions | C++ Tutorial
8:19
Portfolio Courses
Рет қаралды 10 М.
Object Assignment | C++ Tutorial
16:23
Portfolio Courses
Рет қаралды 7 М.
The IMPOSSIBLE Puzzle..
00:55
Stokes Twins
Рет қаралды 28 МЛН
У вас там какие таланты ?😂
00:19
Карина Хафизова
Рет қаралды 21 МЛН
Object Oriented Programming (OOP) in C++ Course
1:30:26
freeCodeCamp.org
Рет қаралды 2,6 МЛН
C++ Programming Tutorial 84 - Classes And Objects
9:11
Caleb Curry
Рет қаралды 86 М.
Static Data Member And Static Member Function In C++
17:19
CppNuts
Рет қаралды 52 М.
Destructor Basics | C++ Tutorial
9:13
Portfolio Courses
Рет қаралды 21 М.
C++ Tutorial for Beginners 29 - Placing Classes in Separate Files in C++
18:33
ProgrammingKnowledge
Рет қаралды 52 М.
Static for Classes and Structs in C++
9:12
The Cherno
Рет қаралды 358 М.
Friend Functions | C++ Tutorial
13:05
Portfolio Courses
Рет қаралды 10 М.
C++ classes: static and instance class member variables and functions [1]
9:38
Professor Hank Stalica
Рет қаралды 6 М.
The IMPOSSIBLE Puzzle..
00:55
Stokes Twins
Рет қаралды 28 МЛН