How to Write a C++ Class
Вставка
- Опубліковано 11 лип 2017
- Check out Amazon Music Unlimited for FREE! ► geni.us/ChernoAmazonMusic
Twitter ► / thecherno
Instagram ► / thecherno
Patreon ► / thecherno
Series Playlist ► • C++
Code Complete (best programming book) ► geni.us/z4Yx
Favourite C++ book ► geni.us/hg9nL
======
GEAR:
======
BEST laptop for programming! ► geni.us/pakTES
My FAVOURITE keyboard for programming! ► geni.us/zNhB
FAVOURITE monitors for programming! ► geni.us/Ig6KBq
MAIN Camera ► geni.us/t6xyDRO
MAIN Lens ► geni.us/xGoDWT
Second Camera ► geni.us/CYUQ
Microphone ► geni.us/wqO6g7K
Drone ► geni.us/RAdI
Slack ► slack.thecherno.com
Stream ► / thecherno
Website ► www.thecherno.com
Facebook ► / thecherno
You're probably the only person out there with this level of production value helping people how to code, keep it up man, you're a real help
I know Im asking randomly but does anyone know a method to get back into an instagram account??
I was dumb forgot my password. I would love any help you can offer me.
@@yaelmilo70 Forgot Password Function: I am not even here baby, I am hallucination
@@anonymouscyborg5610 And I started to realize: I am not hallucinating, I am the hallucination. I have become hallucination. The Destroyer of sanity
@@yaelmilo70 if you send me $100 i wont get your instagram account back but I will use the $100 to buy myself a new mouse :)
0:42 Damn you dynamically cropped the amazon logo with your arm for only 5s of video. I'm impressed!
you do know he can do that automatically right?
Nop i’m a low-skilled video editor ^^’
@@krakor92 he may be used adobe after effect for the 3D text.
This is one the nerdiest comments I have ever seen in a nerdy video!(I mean in a good way of course!)
Had you not pointed it out, I might not have known
I'm glad you got sponsored. Heads up for the company that financially reward people like you who spread knowledge
3:14
"Alright there we go done, _can I go now?_ "
literally almost every student in every school ever
3:13
Me in classroom literally every second
9:50 cherno: "this class is trash"
me who worked 1 and a half hour copying and expanding on this class: T_T
same
LOL! 😆
resonating with the collective "bruh" of 260+ people around the world
fr
Log class done, can I go now. LMAO
I spat my coffee lol
Yes, was def funny haha
I don't get it.
@@sha1_________________54 3:10
@@martingaens2073 that was 8 months ago but thanks for explaining the joke
I started watching this C++ series and I just wanna say, you're awesome at presenting and communicating this information! I have some surface-level knowledge of these concepts already, but I can tell I'm learning quite a lot from these videos already. Thank you for sharing the knowledge you've gained with experience, and so concisely.
How u doing now?
how its going ur learning?? you became a great dev in this 2 years or quitted?
Nice! very interested to see how you improve this.
Thanks!
So grateful for your channel, honestly!! Saving me a day before midterm
Great! Looking forward to seeing how you adapt this to be 'production' code.
Like your style, clarity, and just the right speed, not too slow, nice and succinct.
Damn, looks like I am going to have to head over to Patreon and do the right thing :-)
Great video! I deffo had a moment like... I would never do this like this lol. But I get why you have done it, and I tried to take away the main syntax and c++ points from it. Thanks!
My university teacher recomended theese lessons in order to prepare me for their own internship, and just a few videos in I'm already learning a lot! Thank you for theese high quality lessons!
Nice to see some sponsors!
I love how you go through what is functionally necessary vs what is convention and standard practice. This does so much to help us understand what is happening and why. I'm super looking forward to continuing through this C++ course and then eventually into OpenGL.
Hey, I was curious to know if you did get into the OpenGL course. I'm doing this C++ right now and wanted to know if i should do OpenGL next or not. I'm interested in both game dev and game design, but I don't know what to start next, but I love Cherno's way of explanation and wanted to know which to do next. Hope you read this and Thanks in Advance!
@srisairayapudi6074 how its going ur learning?? you became a great dev in this 6 months or quitted?
I went ahead and named the log level variables LevelWarning, LevelMessage, and LevelError instead of LogLevelX because when you write them out outside of the class, you get Log.LogLevelX which is a bit redundant and Log.LevelX reads a lot better. Nitpicks out of the way, very informative tutorial as always!
I've watched a few of your tutorials now and wanted to say big thank you for the effort you've put in. Always nice listening to someone who is enthusiastic about what they do and communicates it so clearly. I haven't programmed in C++ since the mid 90s and even then my skills were a bit hit and miss. It's been a steep-ish learning curve getting to where I need to be to programme plug-ins for After Effects, and you are definitely helping me all the way! Thanks and merry Christmas!
Omfg dude. what the hell is this?
I have been reading articles and books and whatnot trying to teach myself code since this whole covid thing went down. I been struggling with classes the last little while. You, though! YOU! thank you! so very much! Also, your conventions are really handy, and help out tons!
I like the structure and speed of your videos as well. All Killer, no filler.
Thanks again! Keep on keepin on!
This is the best C++ series I've seen on youtube. I know how to program, just trying to get a handle on the language and the syntax. Thanks man.
Second time watching these. What an amazing series thank you!
Your channel is a treasure! Thanks!
Good video man. Thank you for the videos, they are helping me learn.
Huge Thank you Cherno!
Please make a series about C, I'll watch everyone of the videos 100x I promise.
This series is addicting, thanks
you are wonderful brother keep going!!!!!
Awesome content! I've been following this tut series from the beginning. Your production value is fantastic and I do like that you cut back and forth between the screencap and yourself talking. However, as a person learning and following along with you and your code, I do prefer to see the screen longer instead of cutting back to yourself. When following coding tuts I let the speaker continue talking as I keep referencing the code while typing to keep up. Unfortunately, the cutaways are so quick that I keep having to stop your video to see the actual code you just wrote.
Again, I love the content and I think your teaching ability is great and super easy to follow along with! But sometimes when you cut back to the screen, the part I'm looking for is now offscreen and I have to skip backward a few times to see what code I missed. Hope this helps inspire future videos. Keep up the great work! I subscribed, and I've been liking all the videos along the way! Hope it helps you!
Thank you for your effort in teaching, I love the way you keep it simple and entertaining yet you don't treat your audience like preschoolers, that kind of condescending language used by some youtubers can get annoying. Subscribed :)
Love the series. I wish I did not have to work a crappy 9-5 and could dedicate my whole time to learning C++. Keep the great content up!
same
I love these videos that you make very thanks for you the cherno
and especially I love that chicken in the background
Rewatching this because I need to remind myself about classes in C++. I'm going to add them to my language pnf. Right now, it should be able to do what C can.
Great idea for a few episodes!
Loving the videos! Thank you.
With programming I'm the opposite: if I really want to focus, I go to silence.
Now, if I want my workday to fly by, music; but that cuts productivity for me (not necessarily a LOT), and these days i would rather be productive.
Commenting for your exposure. The best channel on UA-cam for C++ !!!
Thank God you explained at the end of the video how you would never use this type of messy code, otherwise I was gonna be over-smart here and write the code neatly. Through the whole video until the the point where you clarify, I was thinking "Noway, he writes this type code. His other videos are the opposite". Nevermind, I am just dumb
Can you also talk about Design patterns and some examples to implement it in C++
I would use Bit Fields for the type of log messages. No need to carry a whole integer for that, but I'm sure you know that. I haven't seen Bitwise operations in any of your other videos. Maybe it's a good topic for a new one.
Cheers!
3:12 How I feel after writing one line of code at work.
how it feels to chew 5gum
Thank you so much for saying that about music.
You really should have done this traditionally from top to bottom. The fact that you wrote in main first, coupled with your fast writing and explaining, resulted in me being pretty much stunned looking at the screen the whole time, failing to follow, and then the video was over. At the end with all the code copied in front of me it helped a lot as a guidance through all the additional replays.
thanks
rad new hairstyle Yan!
You are an absolute legend
Thank you brooooooo
Nice video. I am really looking forward to the next one.
Could you use an enumeration type for the log level warning?
The best part of the video is after 10 minutes when you say this is not the way it is done. Great, thank you very much. 12,000 people probably thank you too.
Thanks for the video
Could u create some video explanation for objects initialization in C++, coz afaik there are bunch of this. Thanks
I really like your videos, and the way you explain things, but as someone with a bit of experience in software development I'd recommend two things: not creating big classes with multiple functionalities (also called Singe Reponsibility Principle in SOLID princples) and not using hungarian notation in modern code, it makes code less readable and can introduce bugs. A really good book by Stephan Roth called "Clean C++" is a great resource to learn to write modern cpp code.
the chuck looks class
Yoooo, thanks for the tutorial. How old are you mate?
*My takeaways:*
1. Convention for writing class member variables 4:48
2. Using more than one public to separate variables and methods 6:10
0:42 *How qualitative do ya want your video to be?*
The Cherno : *Yes*
How did you get the sponsorship from amazon ! i mean that's really cool!
This is a godsend
Amazing
Can u plz make a video showing all the special keywords that help u code so quickly?
You have the best videos in c++
Thank you so much for such cool content
Unfortunately, this video stopped displaying any automatic subtitles after 2 minutes, which made it difficult to translate the meaning of the text
But still, thank you for having such high-quality content thanks to you
Amazing series, I am learning a lot with your videos. Just a quick question, I don't know if it might be in another video, what is the difference between . and :: when calling variables/functions from another class?
Member selection vs namespace resolution
It got a little complicated in a short time but your explanation skill handled the complexity very well... tough I won't recommend this series to absolute beginners who just thought of learning C++, you might have to know a little about these concepts before following this this series... but its no harm to follow even if you are a beginners, its just that you might have to search a lot of things to get the idea what's really going on here
overall i would say its a great series... its good that we get all the useful information in just short amount of time 😊
Why does your hair look so different every video.
Implemented with a random seed... :D
Man can wait to see good code version of this. I didn't think if was that bad, with a few changes. But then I guess this is why I need to watch pros like you and learn.
It is pretty decent code for your small side project. You really don't want to get overcomplicated with some basic code that nobody except you will ever touch.
The professional level code will be full of conventions that make working in a large team more productive. It can even help you in your large side projects, as you cannot always remember what everything is supposed to do. Large projects, even made by single person, tend to bring moments of "did I wrote this garbage and why?"
What is optimized method using different concept?
I really wonder how does it work. Do you have a plan to create a video in order to keep continue next video?
6:30 Why not use enums? :O
i did put Enum in there just to delete it few seconds later... 9:58 here is answer.
A little thought I had about a better way to implement this - make m_LogLevel an int that stores flags corresponding to different levels. For example, the warning's if clause could be if(m_LogLevel && logLevelWarning){...}. The user could define more than just three types of messages to print. Maybe define a struct called logMessageType that holds a const char* and a bit mask (set to 2^N), which the log class could use to display that message type (using the const char * when printing the message type, eg "[GRAPHICS]: OpenGL is deprecated" using a list of those structs
Maybe that struct can also hold which color to use when printing?
I liked that hair, it looks like the Final Fantasy hair, it looks fantastic.
Can you please do a video on pIMPL idiom/method?
Good thing he clarified at the end, i was worried for a sec haha like if i gave that type of code to my teacher, i have negative mark lol
Where is the improved version or how would it be improved?
super! love your channel alot. Finally, i can understand many C++ concepts which made me very confused during university years
9:55 You really should have said that in the beginning 🤣. I was freaking out that there was something that I was missing, but it really was just a simple, categorizes I guess? message executor.
So, the next episode will be enum, right?
Or static methods/attributes. Since he always has to create an instance of Log. If he wants to use the Log functionality in basically every other class, he has to handle the same instantiation in all of these classes (unless he wants to use different instances.. but I don't think that'd be the point). It could even go as far as to show the concept of singletons.
Unless he needs the Log object to persist, creating new instantiations at the log site wouldn't be that bad, no reason to keep a pointer/reference around. In the example, there is few members and instantiating a class like this wouldn't be too expensive and there wouldn't be a need to have the object to persist. If you are writing out to the console then all messages will be appended, if logging to a file, you can open in append mode, and the message will be added to the end for you. This way, you won't keep a file open longer than you need. Plus, having different instantiations would allow you to log different aspects to different files with the same interface.
Josh Smith Great note. As always, it all depends on what exactly are you trying to achieve.
Sure, if you talk about a project of that size. But I think he will always plan for the future. And then you have to consider about something like that. You'll have your huge engine and then you don't want to instantiate a new instance of log all the time. And logging into different files with the same instance isn't a real problem too. You can organize the different log types within enums and thus use them to chose from different files to write in.
makes no sense the number of views vs number of Likes
Tks for the wonderful job!
great
Shouldn't the LogLevels be an Enum or at least static?
does anyone know why he uses the pointer at line void Warn ( const char* message )
is it necessary to use it, as I known pointer to store the address and value of a variable so what its role in there?
can anyone explain?
thanks so much
Hi Cherno, I have a question about the meaning of this statement: const char* message. Why did you use pointer? Can we use "string message" instead of this statement?
You rock
"A lot of you watching this video being like 'what code even this is'". I am absolutely not one of them and feel this is exactly how i will write log class.....
3:12 legit me eveytime I start coding
Couldn't you use an enum for log level?
oh man....this is the first video I didn't understand.
_Me after finishing my hw in the detention room_ 3:14
6:45 enums?
Because this video about classes not enums.
Love this series, probably the best on youtube for C++. However, this class was the single most boring class ever coded on video!
i really like this hairstyle
I'm not here for programming tutorial.
I'm waiting for the chicken to move!
Where did you buy that jacket bro?
I took a class on java last year, and c++ classes looking almost identical to java classes
what does the cherno mean?
Hey Cherno, love your videos.
can you make a video how can I make a object array, that each object can call the same function but the outcome is different to each one of those functions. (like for example a class that draws multiple randomly generated bitmaps for example)
thanks in advance!!
If you mean method overriding, then he will most certainly make a video about that.
Bondy Magnomous I suppose, I don't yet understand everything, I'll be looking forward to it, thanks.
Also look into polymorphism , it will certainly allow you what you want to do
Hello! I know this is video was uploaded 1 year ago but I need to ask this question. What's the difference between header and class? I am aware that you'd need to include header file such as #include, but isn;t this same? Aren't headers used to make things more prettier(aligned)?
I'm not sure if you still need the answer but traditionally, when you're working on a big project, you might use header files to define classes. You're pretty much right that its main purpose is organization. Also, in c++ you include your header files as #include"class.h" instead of using But basically a header file is just a separate file that interacts with a .cpp file and it mainly consists of class definitions. Yikes I hope I even understood the question @.@
I wonder why you never lost a word about unions so far. Please talk about as well.. tks
I have a question. When you did not set "log.SetLevel(log.LogLevelWarning)" why did it print all three? If we didn't set it, shouldn't it give us an error? Or does the program set a default value like 0?
Why we used a pointer for the message variable ?
log.SetLevel()
------^------------
Is the standard different from Java? Am I thinking too much into it?
I noticed this too. Maybe this will be detailed in the future and was done on educational purpose here.
It's just a matter of preference I'd say, but the win32 api has the first letter capitalized in functions.
There is no standard notation in C++, though the standard reserves some specific notations (things like the double underscore, which you shouldn't be using). In the end it's about what works best for you and as long as you're consistent with it, other programmers will not find it terribly difficult to adapt to your code. Consistency is a lot more important than what exact notation you use.
is it bad if i dont understand some of this code but i understand the majorty of it?
I know this has been a while. I have 1 parameter that says the name of the log file. also I added critical sections because I have lots of calls that needs logging in many threads.
I'm hoping to see that 1mill Subs soon!! subbed with my all 10000 accounts 😏😆😂