C++ for C programmers — lesson 1 (classes, constructors, methods, templates, is it efficient?)



Are you familiar with C, or with languages based on C? This video gives a quick introduction to C++: a very small core set of things that are new in C++ compared to C. [Subtitles/Captions available]

Topics covered, in order:
– Bidirectional linked list in C
– What is a class (it is a struct)
– Methods
– Struct is a type (typedef is not needed)
– Constructing and destructing
– Template classes
– std::list is already in STL (C++ standard library)
– performance impact (none at all)

Twitter:
Patreon: (alternatives at
Twitch:
Homepage:

Things I forgot to mention:
– methods (member functions) do not increase the size of the struct/class at all. They literally work just the same way as the original C code in this video works, even though they’re defined in between the struct’s { and }. Memory usage per class instance is not increased (and scalability is not hurt), no matter how many methods the class defines.

Topics intentionally omitted for clarity and brevity, even though they would be good style for this program:
– copy constructor / assign operators
– member initialization in constructor
– public and private
– std::string rather than const char*
– const references rather than T verbatim
– exception safety

It’s been a while since I last published videos containing English speech. I think I’ve taken a step backwards towards robotic speech, due to lack of practice. Sorry about that. English is still not my native language!

Same lesson in HTML format:

source

36 Comments

  1. ew, struct prefix before every struct name, JUST use a typedef lol

    typedef struct MyStruct {
    // …
    } MyStruct_t; // the final name doesn't need the _t

    You do not need to put in "struct" before the struct name anymore.

  2. I learned C++ and used it for about 10 years. Now I prefer to use C for a couple of reasons. I'm tired of all the hacks that are necessary to use OOP properly. Everything you call a "design pattern" is a hack around the limitations of OOP. A lot of them are not "simpler" and "more clear". It has failed to deliver on its promises of being more reusable as well. Unless, you use another design pattern you risk tightly coupling all of your codes logic together. Another thing is, it encourages using data structures that are overkill when a simple pointer or c array would suffice. The downside to using C is that when you need sophisticated data structures you either need to build it all from scratch yourself or search for a library online. Even for simple things to replace std::vector. But a lot of people will tell you, when learning C++ you should try rewriting a lot of these containers yourself anyways to learn the language…. So… yeah… just rewrite the containers in C to learn the language then you don't have to worry about it. Smart pointers also risk suppressing memory leaks from debuggers like valgrind… anyways.

  3. sir, i have some questions 1) why char * works as a strings and char var[] works as array of strings and similarly char * works as array of strings ? i searched many ways but didn't got satisfied answer.
    2) which pc is best for all level programming (ram, intel's processor operating system etc) because i have to change my existing one it hangs quite well.

  4. I posted a comment here earlier regarding your implementation of the linked list and a question I had regarding it, but I deleted it because I figured it out. Basically, when I read your code I didn't see your constructor and thus I didn't see that you null-initialized the *first and *last pointers. Thus, I was confused when I read this line

    if(newnode->prev) newnode->prev->next = newnode;

    Since I didn't see the constructor and the null-initialization of the first and last pointers, I assumed this if statement would evaluate to true and then proceed to dereference garbage. All is good now, though!

  5. I would love to see a 'C for C++ programmers' video. Most of us who learned C++ often rely too much on the nifty features and algorithms of its standard library and we turn into babies whose pacifiers have been stolen when we use C without these abstractions.

  6. Thanks for it!. I'm learning C++ because most of the documentation of opengl is written with this. But I only know C.

    Why is necessary use auto in C++? Why isn't better just declare the real value of that variable?

  7. me after study my ass off of C and think to myself "now i finna understand something on that finnish guy's videos" came here, 20 secs, strong headaches, don't understand shit after 5 lines of code.

  8. I just felt like programming for a change, and brushing up on how a "list" internally work, using your C code really helped clearifying the internals of a list that is somewhat equal to std::list. I think the most confusing part of how iteration works in C++ is the list::end(), which you wrote as "return NULL". The conflict here is that you send in a list object (pointer to it), but never use it and return a constant NULL, which I wonder if it could have been redesigned or if it is required for iterating more complex std:: objects? I kinda already know the answer: Too many checks for NULL required for a simple loop, but still. It feels like it could be more clever made, somehow?

Leave a Reply

Your email address will not be published. Required fields are marked *

You might like

© 2026 Cantinho do Vídeo - WordPress Video Theme by WPEnjoy