Static for Classes and Structs in C++

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 พ.ย. 2024

ความคิดเห็น • 321

  • @bredmond812
    @bredmond812 5 ปีที่แล้ว +527

    I wouldn't recommend Cherno to somebody that hasn't had some exposure to coding yet, but after having watched many other people talk about coding at a basic level, im now ready to hear Cherno approach lessons from a higher level concept and not just simple code instructions.

    • @jacoblee5648
      @jacoblee5648 4 ปีที่แล้ว +42

      I agree! I'm a web developer and studied c++ only in school like 5 years ago and never used it until now. I kinda have basic understanding of c++. This series is perfect for me as he explains along with memory things which I definitely need to understand for a reverse engineering.

    • @bredmond812
      @bredmond812 4 ปีที่แล้ว +20

      @@jacoblee5648 Yeah, in fact, i had to put Cherno aside and get even more solid on the basics. Will be back. Would recommend to a friend.

    • @zzedixx
      @zzedixx 4 ปีที่แล้ว +7

      im actually good, but i think its because i come from another programming language, and i just have to get the syntax and i can easily follow along with cherno's videos

    • @bredmond812
      @bredmond812 4 ปีที่แล้ว +2

      @@zzedixx Honestly, I have had to go back to simpler content, LUL

    • @amankaushik5833
      @amankaushik5833 4 ปีที่แล้ว +15

      If you start by watching the first video in the series and follow the series from the start it becomes quite easy. In my opinion Cherno explains everything in way even a beginner can understand and I am sure that its not that difficult to understand C++ for beginners.

  • @HobokerDev
    @HobokerDev 7 ปีที่แล้ว +234

    I love this series. It really is the proper way to learn. Straight to the point but not ommiting important details. I especially like how you treat viewer like a thinking person not a dummy who needs everything pronounced. Keep up the good work and pointing someone to the best C++ tutorial series will be really easy.

    • @marflage
      @marflage 5 ปีที่แล้ว

      And probably that is why you have your display image set to C++ logo?

    • @brandm5176
      @brandm5176 4 ปีที่แล้ว

      You are right about dummy part!

  • @gonzalochristobal
    @gonzalochristobal 4 ปีที่แล้ว +60

    I'm not sure if I ever learned a programming language this well, thanks for all the insights

  • @leixun
    @leixun 4 ปีที่แล้ว +157

    *My takeaways:*
    1. Static variables that are inside a class are shared between class instances 0:29, like global variables for the class
    2. Static methods have a similar effect 1:10
    3. Why we want to use static inside a class 4:50
    4. Static methods can’t access non-static variables 5:35

    • @kylejones1336
      @kylejones1336 3 ปีที่แล้ว +18

      I know this is a year old but I just want to say I love these takeaways in the comments. I appreciate you.

    • @leixun
      @leixun 3 ปีที่แล้ว +4

      @@kylejones1336 Thanks

    • @kylejones1336
      @kylejones1336 3 ปีที่แล้ว +4

      @@leixun Were you a beginner programmer when you started this or were you just learning more?
      I just started really learning programming about a week ago and this is a lot to take in.

    • @leixun
      @leixun 3 ปีที่แล้ว +4

      @@kylejones1336 When I took this course, I was a beginner in C++. I have to say this course was difficult for me and still is. So I just takeaway as the best as I could. You can check out a channel call freeCodeCamp, both channels are very good and provide different perspectives. More perspectives are good fur us as a learner.
      Happy learning! If you use LinkedIn, you can find me there.

    • @kylejones1336
      @kylejones1336 3 ปีที่แล้ว +1

      @@leixun Have your programming skills progressed nicely? Also I have watched FreeCodeCamp I don't really like their inconsistency of teachers, some of them just seem like they are telling me what they are doing and not why.
      Also not sure what LinkedIn is but I am having severe difficulties retaining a lot of this information. I have started a text based game project to help me retain the information.
      Best of luck mate!

  • @saguaroh9407
    @saguaroh9407 ปีที่แล้ว +27

    For those wondering about the 3:00 mark with the initializations, you must initialize static members at global scope, not within a containing class definition, unless they are 'const'.

  • @GfastGao
    @GfastGao 6 ปีที่แล้ว +8

    I'm a pretty intermediate guy in C++. I found this series are actually pretty perfect for people like me => Understand most of the parts of C++ which C++ is sharing with other computer languages (PHP, Javascript, Java...), but still wanna understand trival topics like this "static" keyword & its meaning in different context.
    Thanks Cherno, this series is wounderful.

  • @octavianpetre9498
    @octavianpetre9498 6 ปีที่แล้ว +22

    After watching this like 10 times, the 11th time gave me a huge revelation. Thank you for this, I really appreciate your channel.

  • @chrishusky1464
    @chrishusky1464 ปีที่แล้ว +3

    I remember how When I first found your channel I didn't like your content, it wasn't bad it was just either too much for me or too slow for me sometimes, but now when I have nearly triple the experience I only watch your videos because I suddenly understand what you mean, and you also say what to do, what not, uses of something, etc, thanks Cherno, you are awesome.

  • @vembukarthick9824
    @vembukarthick9824 3 ปีที่แล้ว +4

    I always need to watch your videos 2-3 times to understand the topics fully, you covered in the videos. you are such a genius.
    You cover the topics that many C++ books have not covered.

  • @thesmokinggnome
    @thesmokinggnome 2 ปีที่แล้ว +3

    Love the amount of depth that goes into these videos. And how he starts to go into deeper detail about things, but it goes beyond the scope of the lesson; I like it because it shows just how much there is a reason for everything in programming. Its not magic, and TheCherno debunks that.

  • @Nox568
    @Nox568 3 ปีที่แล้ว

    Man, either your explanations are really good, or C++ is just refreshingly "simple". I feel like in other programming languages, when you truly want to understand something, you reach a point where you just kind of have to accept that "that's just how x works". Not here, everything is so simple and easily constructed, that it just makes sense.
    What triggered me to say this is your explanation of static methods not being able to access member variables. And how you explained that a class method is essentially just a function that's been passed an "invisible" parameter holding the class instance. This, in combination with the earlier videos where it's explained how C++ code is turned into machine instructions, just makes me feel like I really understand what the computer is doing when I write the code. Amazing. Thank you so much for this series.

  • @exrebok1
    @exrebok1 4 ปีที่แล้ว +4

    That background is sweet, quite classy and ultraprofesional

  • @kenamreemas3295
    @kenamreemas3295 6 ปีที่แล้ว +25

    many people are asking the same doubt "why declare those vars outside the class"..
    okay, try thinking it like this way, these variables belong to a structure or class, But being static, they are not a part of the object of the class. So when an instance of a class is created, all the members of the class which are not static are declared, because static members are not a part of any instance, so to use them, we have to bring them to a scope from where they can be accessed.. so they need to be declared outside the class.. just to bring them in a scope where they can be accessed from. like a global variable.

    • @Katatonya
      @Katatonya 3 ปีที่แล้ว

      I was confused too because I remember using static variables in C#, and not needing to define them outside the class. Can anyone explain why that was? Is C# just automatically defining those as global variables for you?

    • @lukostello
      @lukostello 3 ปีที่แล้ว +6

      that just moves the question to "why are they in the class in the first place?"

    • @pascalladal8125
      @pascalladal8125 2 ปีที่แล้ว

      All right, fair enough. Then why don't we have to declare static functions? They're not part of any instance as well.

    • @SakshiSingh-arcane05
      @SakshiSingh-arcane05 3 วันที่ผ่านมา

      @@pascalladal8125 Because the static functions don't need memory allocation explicitly, whereas static variables require memory allocation and hence need to be defined outside the class for the runtime to allocate memory

  • @krec348
    @krec348 7 ปีที่แล้ว +29

    Tons of doubts were cleared!! Thank you!

  • @francobarrera5327
    @francobarrera5327 ปีที่แล้ว

    God damn Cherno, I cannot share all my admiration to you on how you explain the behind the scenes in this c++ series. I love your work man, great job and thanks! ♥

  • @mawke1918
    @mawke1918 2 ปีที่แล้ว

    Love it how he actually explains everything in the intro so you can just go back to a video to remind yourself

  • @EpicVideoGamer7771
    @EpicVideoGamer7771 2 ปีที่แล้ว

    I have been sick and this series has been helping me get through the discomfort. tysm :D

  • @jockinafrock
    @jockinafrock 6 ปีที่แล้ว +2

    Hi TheCherno. Fabulous series. I'm trying my hardest to follow along (despite the breakneck speed of your lessons!). I'm astounded by your depth of knowledge of coding, and it shows in your explanation of abstract concepts. I'm just about getting it, but it will take me several run throughs. Really appreciate your efforts on putting this series together.

  • @morana7164
    @morana7164 ปีที่แล้ว

    Man this guy is a master. So thorough and clear

  • @abdelrhmanahmed1378
    @abdelrhmanahmed1378 4 ปีที่แล้ว +27

    Static member data requires an unusual format. Ordinary variables are usually declared (the
    compiler is told about their name and type) and defined (the compiler sets aside memory to
    hold the variable) in the same statement. Static member data, on the other hand, requires two
    separate statements. The variable’s declaration appears in the class definition, but the variable
    is actually defined outside the class, in much the same way as a global variable.
    Why is this two-part approach used? If static member data were defined inside the class (as it
    actually was in early versions of C++), it would violate the idea that a class definition is only a
    blueprint and does not set aside any memory. Putting the definition of static member data outside
    the class also serves to emphasize that the memory space for such data is allocated only once,before the program starts to execute, and that one static member variable is accessed by an
    entire class; each object does not have its own version of the variable, as it would with
    ordinary member data. In this way a static member variable is more like a global variable.

    • @imscaredofmoney
      @imscaredofmoney 2 ปีที่แล้ว +1

      Thank you!

    • @noblenoble7943
      @noblenoble7943 หลายเดือนก่อน

      Thank you! I notice form your name that you are an arab i'm too and my guess you are an egyptian right? I'm too :D

    • @abdelrhmanahmed1378
      @abdelrhmanahmed1378 หลายเดือนก่อน

      @noblenoble7943 right. Your reply after four years brought back some memories.

  • @themptytree3145
    @themptytree3145 3 ปีที่แล้ว +16

    Think of Pacman! "Ghost" class could have a static bool "eatable". When the character consumes an "energizer" then by setting "eatable" to "true" all the ghosts would become vulnerable, and there is no need to set "eatable" to true for each of the ghosts!

  • @Cynokine
    @Cynokine 7 ปีที่แล้ว +2

    Thanks, as it happens I recently run into this problem in C++ and although it wasn't a blocking problem, it's still good to know the why and how. Keep this great work, I hope you enjoy making this series

    • @kevz3351
      @kevz3351 3 ปีที่แล้ว

      You look like levy, GothamChess

  • @wintersoldier76251
    @wintersoldier76251 ปีที่แล้ว

    Probably the best explanation of static I've ever heard.

  • @diegomora997
    @diegomora997 2 ปีที่แล้ว

    Bro thank you so much, this course is like reading a C++ book, youre the best.

  • @mastershooter64
    @mastershooter64 ปีที่แล้ว +3

    3:04 btw instead of defining them again, since C++17 you can also use the *inline* keyword to avoid doing that. so inside your struct you would just do "inline static int x, y;"

  • @juanpablogomezgarcia1835
    @juanpablogomezgarcia1835 4 ปีที่แล้ว

    It's incredible the way you explain this

  • @Xx_McJasper_xX
    @Xx_McJasper_xX 3 ปีที่แล้ว

    Short and sweet. Glad I watched this, because I always thought static was a synonym for global variable.

  • @slayerfiend
    @slayerfiend 4 ปีที่แล้ว +1

    i watched this for the 20th time and now i am begining to under stand thank you charno

  • @justinlynch6691
    @justinlynch6691 7 ปีที่แล้ว +1

    Your videos are incredibly efficient, and explained so well. You've saved me hours/days of digging through garbage.

  • @timizzard4317
    @timizzard4317 4 ปีที่แล้ว

    This is the first video of his I felt confused about, I'll make a mental note to learn and experiment about static from other resources, but continue on with the series

  • @anthonyhalim926
    @anthonyhalim926 6 ปีที่แล้ว +2

    In JS, classes work in similar ways in the sense that every function has a hidden parameter to it that dictates what `this` is bound to. But never realise that it is the same case for C++. Great information!

  • @charliesoandso
    @charliesoandso 4 ปีที่แล้ว +19

    Cherno: I'm in some Czech hotel... just don't ask questions...
    Me: OK, I like a challenge.

    • @ciinoxgaming
      @ciinoxgaming 2 หลายเดือนก่อน

      You asked no question

  • @shvideo1
    @shvideo1 3 ปีที่แล้ว

    An excellent and to the point explanation. It's beyond me why there is even one thumbs down! Great job and thank you for producing these series.

  • @yassinelakbir2515
    @yassinelakbir2515 4 ปีที่แล้ว +1

    I did take a course on c++ in college a year ago upon that time I did really understand things very good, but I've never take my c++ to next level because I didn't build anything with it, and now I'm using the Chrono series to review concepts so I can now advance and participate in open source projects

  • @shulehr
    @shulehr 2 ปีที่แล้ว

    man, those statics are nuts

  • @sleep3017
    @sleep3017 4 ปีที่แล้ว

    Totally an underrated channel

  • @ConspiracyCraftersStudio
    @ConspiracyCraftersStudio 3 ปีที่แล้ว

    one of the most valuable lessons in c++

  • @ssuriset
    @ssuriset 4 ปีที่แล้ว +8

    Every sentence coming out of his mouth is gold.

  • @mikeorioles
    @mikeorioles ปีที่แล้ว

    Great for a refresher. Thanks!

  • @Stelios.Posantzis
    @Stelios.Posantzis 5 ปีที่แล้ว

    Excellent series. Best place for a newbie to start learning.

  • @teachyourselfcs
    @teachyourselfcs ปีที่แล้ว +1

    Wow this is way too good. Why can't everyone teach like you do?

  • @ali.sheharyar.sheikh
    @ali.sheharyar.sheikh 7 ปีที่แล้ว +3

    The quality of these tutorials are amazing!
    You are redefining the way programming tutorials should be made.
    Love and Respect for you Bro from PAKISTAN :)

  • @clashwarner4679
    @clashwarner4679 5 ปีที่แล้ว +2

    These videos are fabulous! Though having proper exercises is my biggest concern! having some short videos or even simple questions would be a blast!

  • @arhantbararia380
    @arhantbararia380 4 ปีที่แล้ว

    I don't how people find reasons to dislike this type of videos.

  • @unfilteredgaming6240
    @unfilteredgaming6240 2 ปีที่แล้ว

    Why is this guy so amazing?

  • @mykedev4377
    @mykedev4377 7 ปีที่แล้ว +2

    A tutorial about multiplatform coding with C++, would be awesome, thanks and excellent videos, subscribed already!

  • @brenotanquista9543
    @brenotanquista9543 3 หลายเดือนก่อน

    perfect explanation

  • @xunhuanlee5892
    @xunhuanlee5892 ปีที่แล้ว

    After using Unreal Engine for a long time, i now know more about C++. few years ago i watched this video but can't understand a bit :p, thank you Cherno!

  • @ejm2e
    @ejm2e 6 ปีที่แล้ว +41

    For "Entity e1 = { 5, 8 };", how did the compiler know which variables to assign to? There was no constructor defined.

    • @carolapedrosa8409
      @carolapedrosa8409 6 ปีที่แล้ว +27

      It uses the implicit constructor that just 'fills in' the variables of the class with the values that you wrote between { }, in the order you wrote them.

    • @cantcode1001
      @cantcode1001 5 ปีที่แล้ว +14

      I had the same question. He should have explained that instead of steamrolling over it at mach 2

    • @aniketahir101
      @aniketahir101 4 ปีที่แล้ว +2

      Its an initialization list bro

    • @vighnesh153
      @vighnesh153 4 ปีที่แล้ว +1

      This is very bad. This should not exist. For programmers coming from a different language background, it will be strange and ambiguous.

    • @OGBhyve
      @OGBhyve 4 ปีที่แล้ว +3

      Vighnesh Raut It exists in other languages like C# too (Assuming you're talking about default constructors).

  • @ren69ade
    @ren69ade 7 ปีที่แล้ว +374

    You should start recommending a quick programming exercise for us every time you show us new stuff. It would be motivation for us to do something on our own after we watch your video.

    • @user_matrix2108
      @user_matrix2108 5 ปีที่แล้ว +10

      I agree cuz just watching won't make u get all the stuff mentioned
      Else what u can do is tryna make quick exercises for urself

    • @FernandoOliveira1979
      @FernandoOliveira1979 5 ปีที่แล้ว +22

      I often do my own exercises after the videos. Just try doing the stuff he does, by yourself, with no aids. Helps a lot. Or grab a book with examples to code. I am not expert in this field, but i like the C++ primer plus. Just study the examples and code by yourself.

    • @des_sun1x
      @des_sun1x 5 ปีที่แล้ว +28

      Its kinda your job to learn, this guy cherno is just doing free teaching.

    • @castro6612
      @castro6612 5 ปีที่แล้ว +15

      Get your exercise on your own, be thankful that he's doing this for free. son of a bitch

    • @govegmofomakeamuffin6620
      @govegmofomakeamuffin6620 5 ปีที่แล้ว +24

      @@castro6612 HEY WOAH

  • @0231-g6z
    @0231-g6z 7 ปีที่แล้ว +1

    The last minute of this video.... BOOMMM!!!!!!! mind opener

  • @siddharthkumar7561
    @siddharthkumar7561 4 ปีที่แล้ว

    Thanks a lot mate, your videos have cleared a lot of my doubts. Love this complete series

  • @wearecode9199
    @wearecode9199 4 ปีที่แล้ว

    This course is definitely not for a beginner :) This course is for those who already know like 2-3 languages and have like 1-2+ year experience and need to fill those 'Why though' gaps - Exactly what i needed !!!

  • @bangnguyen8298
    @bangnguyen8298 7 หลายเดือนก่อน

    To be honest, thank you so much for your valuable sharing

  • @testvb6417
    @testvb6417 2 ปีที่แล้ว

    love the cherno

  • @work9167
    @work9167 3 ปีที่แล้ว

    This is a wonderful explanation!

  • @vb9950
    @vb9950 ปีที่แล้ว

    After this video! I understood more about Python and why class methods are either being passed a self or cls.

  • @gokulsreekumar4371
    @gokulsreekumar4371 3 ปีที่แล้ว

    This is Eye opening

  • @adamhendry945
    @adamhendry945 3 ปีที่แล้ว

    Fantastic video!! Your work is great!

  • @matiasdaneri1142
    @matiasdaneri1142 7 ปีที่แล้ว +40

    I didn't understood at minute 3:20, why it needs to add the definition if it was the declaration on the class?

    • @jjjobs5867
      @jjjobs5867 6 ปีที่แล้ว +25

      In C++, static members must be explicitly defined.

    • @timkellermann7669
      @timkellermann7669 6 ปีที่แล้ว +15

      if it would be only defined in the class it would get defined every time this class gets created so it has to be created outside the class otherwise the compiler forbits this because it makes no sens

    • @obong5241
      @obong5241 6 ปีที่แล้ว +2

      I think declaration of static member variables in class doesn't mean those variables are set in the memory. So, You have to declare the variables outside the class(Initialization).
      But, the method has already been set in the memory and you can call the method as long as you declare the static member variables before. but if you don't declare the variables, and call the method, there will be link errors.
      Not sure if i said right. The best way is have your hands dirty on your own :)

    • @anthonyhalim926
      @anthonyhalim926 6 ปีที่แล้ว

      From readings that I have gathered, this is (partly) so that the compiler can initialise the value for the static members. So, for example, the x variable, by typing int Entity::x, we initialise x to be equal to zero. This is different for non-static variables where there is no initialisation of value.

    • @JamesStocks
      @JamesStocks 5 ปีที่แล้ว +1

      @@timkellermann7669 This makes it seem like the static int in the struct is just somewhat of a reference. There needs to be a singular explicit definition for the variables.
      This makes sense, but it's another place where it would be kinda nice if the compiler just took care of it.

  • @ahmedasaleh6547
    @ahmedasaleh6547 ปีที่แล้ว +2

    Question!
    Why do we need to declare static variables (like: int Entity::x) but not static methods (like: void Entity:print() )??

  • @h.hristov
    @h.hristov 7 ปีที่แล้ว +1

    Thanks again lad, love your videos!

  • @mikicerise6250
    @mikicerise6250 3 ปีที่แล้ว

    "This is what a non-static function looks like when it's compiled".
    *head explosion* Of course! Of course it does. It all makes sense now! Thanks Cherno. I hadn't made that click yet. :D

  • @akiyprum
    @akiyprum 2 ปีที่แล้ว

    Thank you so much for this

  • @ayushbajaj1965
    @ayushbajaj1965 3 ปีที่แล้ว +1

    You are great!

  • @chainonsmanquants1630
    @chainonsmanquants1630 4 ปีที่แล้ว

    Thanks ! What a Teacher !

  • @TheKnightTeutonic
    @TheKnightTeutonic ปีที่แล้ว

    U are one great person man

  • @cpadude123
    @cpadude123 4 ปีที่แล้ว +1

    live from Versailles, it's Cherno!

  • @raghavsrivastava2910
    @raghavsrivastava2910 3 ปีที่แล้ว

    Amazing Video.

  • @timgoppelsroeder121
    @timgoppelsroeder121 3 ปีที่แล้ว

    the c++ god returns

  • @Nerfdalocks
    @Nerfdalocks 6 ปีที่แล้ว

    Great video, makes a lot of sense. Thanks!

  • @Raul-ef6ct
    @Raul-ef6ct 6 หลายเดือนก่อน

    Life saver

  • @maciejpokora8238
    @maciejpokora8238 4 ปีที่แล้ว

    meritorical video, i like it

  • @Chrisymcmb
    @Chrisymcmb ปีที่แล้ว

    This is good.

  • @rcookie5128
    @rcookie5128 7 ปีที่แล้ว

    Awesome video as always! Could you explain the principle of a singleton in c++ next please? :)

  • @helpfulsquid2502
    @helpfulsquid2502 3 ปีที่แล้ว

    Python really helped me understand what that hidden parameter in classes is, as in python, it's not hidden

  • @w3w3w3
    @w3w3w3 5 ปีที่แล้ว

    Thanks. Interesting as always!

  • @PRED122
    @PRED122 ปีที่แล้ว

    I just found that I can use static to create semaphore. That's amazing.

  • @Gr0nal
    @Gr0nal 3 ปีที่แล้ว

    So if I understand correctly, an example of wanting a static variable in a class would be something like a modifier that you want to affect all instances of the class. Say you have a class for an enemy in a game, you could modify their health or speed, etc, values. So it would be a way of every enemy having a base health, but then you could up the difficulty with a health modifier static variable.

  • @Sweettoontown
    @Sweettoontown 6 ปีที่แล้ว

    Thank you very much ! :)

  • @deepakprajapati2635
    @deepakprajapati2635 4 ปีที่แล้ว +5

    An interview question: How will you throw an error if more than 5 objects of a class are created at a time
    Solution: use a static variable count to track the no. of objects. increment count in constructor and decrement in destructor

  • @Zerefse
    @Zerefse ปีที่แล้ว

    Thanks😊

  • @BlueDippy
    @BlueDippy 9 หลายเดือนก่อน

    Thank you holy shit, all these TH-camrs using these long robust definitions for what it is like it’s some sort of derivative of quantum physics.
    “Using static for a variable within a class means there will only be one instance across all classes/objects” fuck was it that hard?

  • @DanielZikmund
    @DanielZikmund 7 ปีที่แล้ว +3

    Which city are you visiting? I am from the Czech Republic as well, the hotels in our capital are very nice, although very expensive.

  • @qixu9482
    @qixu9482 6 ปีที่แล้ว

    Thank you very much for these C++ lectures, learned so much about the language, really appreciated, I hope you keep making these videos.

  • @serkanozturk4217
    @serkanozturk4217 2 ปีที่แล้ว +1

    Personal Notes:
    - if you use it for variable, it is the same variable for all instances, i.e. if one instance changes that static variable then it is changed for all the other instances as well
    - a static method can be called without a class instance
    -static methods cannot access non-static variables, the reason is: static methods do not have a class instance(recall that all non-static methods of classes take that class instance as parameter)

  • @pascalladal8125
    @pascalladal8125 2 ปีที่แล้ว +1

    I'm wondering though why we wouldn't declare static functions as we declared static variables.

  • @null-0x
    @null-0x 2 วันที่ผ่านมา

    What is difference between Static Class Methods and regular functions?

  • @deniz7559
    @deniz7559 3 ปีที่แล้ว

    Why does the initializer fail at 2:40 and not the three lines above?
    Thank you!

  • @NikhilAsawadekar
    @NikhilAsawadekar 3 ปีที่แล้ว

    can you please explain what is the need of 3:11? That part was confusing.

  • @exnaruto1
    @exnaruto1 7 ปีที่แล้ว

    what is this magic :o! another video!

  • @TheShadoDragon
    @TheShadoDragon 7 ปีที่แล้ว +1

    Any plans for making a tutorial about CMake in the future which also shows the advanced stuff? I would really like to know how a proper and professional CMake setup looks like for C++ as I'm always struggling to get anything done with CMake.

  • @samahsamiee9659
    @samahsamiee9659 5 ปีที่แล้ว

    Hi, I was wondering if anyone could help me out with a few questions. I would really appreciate it!!
    1. Why is it that when static was used at 2:45 they are no longer class members? The reason why I'm asking this is that why does e.x and e.y work (btw is there a term for this kind of instantiation?) if they aren't class members?
    2. This is probably the main question people were asking on why we needed to define the static variables outside the class? I read this comment by Ranziger saying that
    "if it would be only defined in the class it would get defined every time this class gets created so it has to be created outside the class otherwise the compiler forbids this because it makes no sense"
    My question is what's wrong with the variables being defined every time the class was instantiated, is it because it would take up more memory or be less efficient? Thanks for the help!

    • @samahsamiee9659
      @samahsamiee9659 5 ปีที่แล้ว

      @Peterolen Thank you soo much, really cleared up my questions!! I'll might have some follow up questions later on, which I'll really appreciate if you could answer. Thanks again

  • @edwarddeaddead1128
    @edwarddeaddead1128 3 ปีที่แล้ว +1

    Oh, so it's just like how statics work in java classes. Thx!

  • @MaxCoplan
    @MaxCoplan 5 ปีที่แล้ว +1

    The whole video makes sense except for the linker error at 3:00. Why would you need to manually define those variables?

  • @TheBoDuddly
    @TheBoDuddly 2 ปีที่แล้ว

    For the most part, at least my understanding is, that if you create static variables in a class or struct it should probably declared as const. Like, the value of pi for instance that you need to access from multiple objects of the class type..Please, correct me if I am worng!?

  • @fabspark1631
    @fabspark1631 2 ปีที่แล้ว +1

    3:20 can anyone explain plz why do we need those lines 'int Entity::x;' 'int Entity::y;'

  • @ahmadashbat
    @ahmadashbat 3 ปีที่แล้ว

    THANKS

  • @CrittingOut
    @CrittingOut 3 ปีที่แล้ว

    so static in a class is like making every instance of objects from the class have the same value for that static

  • @pwlegolas3
    @pwlegolas3 4 ปีที่แล้ว

    great video !!!