Search

C.1 — The end?

Congratulations! You made it all the way through the tutorials! Take a moment and give yourself a well-deserved (insert something you enjoy here).

Now, after breathing a long sigh of relief, you’re probably asking the question, “What next?”.

What next?

By this point, you should have a solid understanding of the core C++ language. This sets you up well to continue your learning journey into other adjacent areas. So if there’s something you’re really interested in learning about, now’s a good time to see whether you have enough knowledge to jump into that.

However, for most users, I think there are a few natural next steps.

Data structures and algorithms

If you haven’t already learned about these, this is my strongest recommendation.

A data structure is a collection of data and a well defined set of methods to access or manipulate that data. The most common data structure used in programming is the array, which holds a number of elements of the same type in sequential memory. You can manipulate the data inside an array by using array indexing to directly access (or modify) the elements inside the array. In the lessons, we also covered the stack data structure, which provide push, pop, and top functions to access the data on the stack.

An algorithm is a self-contained set of operations that typically manipulate or calculate outputs from the data in a data structure. For example, when you look through an array to find the median value, you’re executing an algorithm. Binary search is an algorithm to determine if a given value exists in a sorted array. Sorting routines (such as selection sort and bubble sort) are algorithms that sort data sets.

Over the years, mathematicians and computer scientists have come up with a fairly standard set of reusable data structures and algorithms that are useful for constructing more complex programs. These all have various tradeoffs. For example, arrays are fast to access data and sort, but slow to add or remove elements. Linked lists, on the other hand, are slow to access data and sort, but very fast to add or remove elements (if you already know where those elements are).

Why does it matter? Let’s use an analogy. If you were going to build a house, you could build all of your tools from scratch if you wanted. But it would take a long time, and you’d probably mess quite a few things up and have to start over (ever created a hammer? Me neither). Also, if you use the wrong tool for the job, your quality would suffer (try nailing in nails with a wrench).

More likely, you’d go to the local hardware store and buy a few tools: a hammer, a level, a carpenter’s square, etc… and then read some internet tutorials on how to use them properly. These would vastly accelerate your house construction efforts.

Data structures and algorithms serve the same purpose in programming: they are tools that, if you know how to use them, can vastly accelerate how quickly you can get things done at quality.

The good news is that many of these data structures and algorithms have already been implemented in the standard library. You’ve already encountered some of these in the preceding tutorials: std::array, std::vector, std::stack, std::string, and std::sort, to name a few. Learning to use these effectively and appropriately is a great use of your time.

If you’re short on time (or patience), learning how to use the most common data structures and algorithms is the minimum you should do. But if you have the inclination, try recreating those data structures yourself, from scratch. It’s really good practice on writing reusable code, and will help you down the road when something you need isn’t in the standard library. But then throw them out, and use the ones in the standard library. :)

The C++ standard library

The bulk of the C++ standard library is data structures and algorithms. However, the standard library contains other things too, and another next step could be to explore those. Among other things, there are numerics (math) libraries, input/output routines, functions to handle localization and regionalization, regular expressions, threading, and file access. Every new release of C++ (which has been happening about every 3 years now) adds a batch of new functionality into the standard library. It isn’t critical that you know how everything in there works, but it’s worth at least being aware of what exists, so that if you happen upon the need for it, you can go learn more as needed. https://cppreference.com/w/cpp is my go-to reference for discovering what exists.

Graphical applications

In our tutorial series, we developed console applications, because they’re easy, cross-platform, and don’t require installing additional software. Unlike many modern programming languages, C++ does not come with functionality to create application windows, or to populate those windows with graphical elements or graphical user interface widgets (checkboxes, sliders, etc…). To do those things in C++, you’ll need to enlist the help of a 3rd party library.

Getting a graphical application up and running requires a few additional steps. First, you’ll need to actually install the 3rd party library and connect it to your IDE, so you can compile it into your program. Most graphical libraries should come with instructions on how to do this for the most popular IDEs. Next, you need to instantiate an OS window, which requires calling certain function from the toolkit. Most, if not all, of the libraries should have sample programs that you can compile and dissect if you’re not sure how to do something basic.

There are a lot of libraries out there, and which one you should use depends on your requirements (you’ll have to do your own research to determine which one is right for you). Popular choices include Qt, WxWidgets, SDL, and SFML. If you want to do 3d graphics, all of these frameworks support OpenGL, and there are great OpenGL tutorials on the internet.

Graphical applications typically run differently than console applications. With a console application, the program starts executing at the top of main() and then runs sequentially, usually stopping only for user input. Graphical applications also start executing at the top of main(), typically spawn a window, populate it with graphics or widgets, and then go into an infinite loop waiting for the user to interact with the window (via mouse click or keyboard). This infinite loop is called an event loop, and when a click or keypress happens, that event is routed to the function(s) that handle that type of event. This is called event handling. Once the event is handled, the event loop continues to run, waiting for the next bit of user input.

TCP/IP / Network programming (aka. the internets)

These days, it’s pretty rare to find programs that don’t connect to the internet, a back-end server/service, or leverage the cloud in some way. Any program that requires you to have an account and log in is connecting to a server and authenticating a user. Many programs connect to some service to check whether an update is available. Social applications maintain a persistent connection to a social infrastructure, to allow users to communicate with each other on demand. These are examples of networking.

Networking (broadly) is the concept of having your program connect to other programs, either on your machine, or on network-connected machines, to exchange information. Networking is a powerful tool -- in the past, if you wanted to change the behavior of your application, you had to release an application update. Now, with some good program design, you can simply update information on a server somewhere, and all instances of the program can leverage that change.

As with many things C++, there are libraries out there to help make your C++ programs network capable. The Asio C++ library is a commonly used one (there are two variants -- a standalone version, and a version that integrates with Boost, which is a library that provides a lot of different functions, much like the standard library).

Multithreading

All of the programs we’ve seen in this tutorial series run sequentially. One task is completed, then the next one starts. If a task gets stuck (e.g. you’re asking the user for input and they haven’t entered any yet), the whole program pauses. This is fine for simple academic programs, but not so great for actual applications. Imagine if your program couldn’t handle the user clicking on something because it was busy drawing something on the screen, or if the whole program paused/froze when a network call was happening. The program would feel unresponsive.

Fortunately, a method exists to allow programs to execute multiple tasks at the same time. This is called threading. Much like how (most of) you can walk and chew bubble gum at the same time, threading allows a program to “split” its attention and do multiple things in parallel.

For example, some graphical applications (such as web browsers) put the rendering (drawing graphics) portions of the applications on a separate thread, so that updating the screen doesn’t block other things (like accepting user input) while the drawing is happening. Network calls are often done on separate threads, so that if the network call takes a while to resolve, the application doesn’t grind to a halt while its waiting.

Threading is powerful, but it introduces additional complexity, and a lot of room for additional errors. Therefore, I wouldn’t recommend starting here -- but it is a good area to learn about eventually, especially if you want to do complex graphical applications or network programming.

Improve your fundamentals

Another option is to spend time improving your understanding of best practices. For this, I highly recommend having a read-through of the CPP Core Guidelines, with an optional delving into the GSL library.

A good bye!

At this point, I’d like to take a moment to thank you for stopping by and reading this tutorial series. I hope you enjoyed your time here and have found this site useful. Special thanks to those of you who have helped keep this website a free resource available to everyone by viewing ads that interest you. Please drop by again!

Good luck (and skill) in your future endeavors, and happy programming! And remember, old programmers never die -- they just go out of scope.

-Alex

PS: If you have any feedback or other suggestions for things to explore next, please mention them in the comment section below.


No next lesson
Index
B.3 -- Introduction to C++17

301 comments to C.1 — The end?

  • Ryan

    Thank you Alex and Nascardriver. I am looking to learn more about Machine Learning and Aritificial Intelligence and start programming in it. I am unsure about the steps I should take in learning and was wondering if you there are any books, sites or places I should consider looking at.

  • 蒋伟

    When you serve others, life is no longer meaningless. Thank you all for sharing

  • Tobias

    I started learning C++ using this website a couple months ago. In August or so I realized that this is way too in depth. Why would I care about C++ 11 or older at all, if theres newer versions with better features? I highly recommend hiding information about old versions, so its available but optional. Also, please, for all future readers, make in depth explanations hidden as well. When a user wants to see detailed explanation, then he should be able to click a button called details or whatever seems appropriate to you. I read so much unneccessary stuff that is not needed at all for still mastering the language. C++ is already huge and this site didnt facilitate my learning process. I just had no way to quit as I committed to this site by sticking to it for too long and I would have likely missed useful information by switching to another site. I am writing this for people who might stumble accross this site, not myself.

    • nascardriver

      > Why would I care about C++ 11 or older at all, if theres newer versions with better features?
      I absolutely agree and I'm making efforts to get rid of lessons that were superseded by new features.

      > make in depth explanations hidden as well
      That's what we do with the "For advanced readers" and "Optional reading" notes. It would have been great if you had pointed out the specific lessons as you read them. Can you name anything from memory that you considered too in depth?

      Thank you for your feedback!

      • Tobias

        I think you don't have to get rid of it. It's still good documentation. But hiding it behind a drop down button would be very helpful. Because when I read this whole documentation, I always had to watch out for C++11 being mentioned and then check how many lines I can skip. And regarding information for advanced readers (if it is marked as such): Whenever I saw information about how things are implemented within C++ or simply all things that are not purely about how to use C++, I thought "well, I don't need this". In my opinion everything that's not purely about implementing C++ of the last 10 years should be optional and hidden behind a button

    • "Everything should be made as simple as possible - but no simpler!" - A. Einstein

  • Jee'Von

    Thank you Alex and Nascardriver. I remember stumbling on this site about two months ago. These tutorials really helped on my path to becoming a robotics engineer in the future.

  • choofe

    @nascardriver
    this is my solution to problem I mentioned earlier

    We shall say that an n - digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5 - digit number, 15234, is 1 through 5 pandigital.

    The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.

    Find the sum of all products whose multiplicand / multiplier / product identity can be written as a 1 through 9 pandigital.

    HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.

    and the fast solution is as follow
    better to be in one place rather that two posts!?

    • nascardriver

      I'll separate this into mathematical, algorithmical and programmatical mistakes. All these mistakes cause your program to be slower.

      Mathematical mistakes
      - `digitsCount`: The number of digits in a decimal integer `i` is `std::ceil(std::log10(i))`. Using a loop is slow.

      Algorithmical mistakes
      - `number1` can't be 1. `1 * number2 = number2` is not pandigital.

      Programmatical mistakes
      - `std::vector` uses dynamic memory allocation. Dynamic memory allocation is slow. You don't need to store your digits in separate objects at all. You're using 4 bytes to store each digit. For a 4 digit number, you're using 16 bytes. That's nuts. Same, but less severe, when you use a `bool` array. You can store all digits in the bits of a single `unsigned int`.
      - You're manually assigning `false` to each element of `digits`. List initialization can do that for you. Loops are slow.
      - You're binding references to fundamental types. Copying them is faster.
      - You've repeated your pandigital check 3 times. Use a function. The compiler will inline the function for you if it thinks that's best. This doesn't slow down your program, but it's bad practice.
      - Use standard algorithms. They're optimized and well tested.

      The faster solution even got away without using a `std::set`, which is possible because of the limited number of results.

      Your biggest problem is probably the overuse of `std::vector`. You're performing a huge number of dynamic allocations. The fast solution uses 1 dynamic allocation, and it doesn't even need that is the stack is large enough.
      Second on the list is probably the bit masking method of the fast solution.
      If you update your code and take time measurements after every change, you'll see what had the biggest impact. Usually a bad algorithm causes the biggest impact, but you've got that right.

      Generally with these kinds of problems, if you think you need to use a standard container, you're doing something wrong. If the optimal solution is crazy fast, it's probably because of a smart algorithm and math. Once you understand the algorithm and math, the implementation is trivial.

      Knowing computational complexity theory will certainly help you compare algorithms and notice early if you're taking a wrong turn in your thinking.

      • choofe

        Hi. this was insane!!!
        I've updated my code regarding as you've said.
        1st: changing 'digitCount' to ceil(log10(x)) it reduce time by third it went from 2.5 seconds to 0.8 seconds.
        2nd:but it was not all. It turned out that the big problem was the vector things (as I was suspicious about already). It seem that I was doing it all wrong.
        the updated code is even faster the fast code!
        I'm very shocked how big is the impact of vectors.
        Here is the updated code:

        this code produces result in 0.00491 sec
        while the fast code example does it in 0.00776 sec
        this is how I get from 3.5 seconds to roughly 5 miliseconds.

      • choofe

        Hi nascar.
        I updated another problem which used just 2 vectors; one a size 10 'int' and a size 10 bool. The problem was to create all permutation of digits 0 to 9 and find the 1 millionth permutation. I extended it to do all the permutation that is 10!=3628800. This vector based does all the number in 99 seconds.
        I updated it to use c style array.
        That reduces the time to 0.4 millisecond. it is the same code just change vectors to c-style arrays. That is like 200 times faster! I know vectors use dynamic allocation memory and has its own advantage like some functions and resizing and remembering its size and... But with this huge difference, does it worth to do some extra code to benefit the speed?
        ---

        • nascardriver

          If you know the size of your data at compile-time, don't use a vector, use `std::array`. A vector is there for data that changes its size at run-time.

          • choofe

            Hi nascardriver!
            I wonder if you have any comment on my updated code.
            And about the std::array: Is it as fast as c-style arrays? And is there any work around to use c-style arrays with unknown size?
            And about your avatar it is more likely a Monster truck rather than a NASCAR car if it's relevant ;)

            • nascardriver

              - You're using a `bool` array to store digits. That's at least 9 bytes, but you only need 9 bits. An `unsigned int` has plenty of storage and is probably faster.
              - Use array syntax to access arrays. Doing so helps your compiler understand what's going on and it might be able to provide better warnings.
              - Duplicate/Triple operation: `number1 * number2`, `number / 10` and `number % 10`. You only need to do these once.
              - Line 30: This is the same as

              - You're using `short`. You probably did this because you thought it's faster because it's smaller. That's probably not the case. Let the compiler choose what's best by using `std::int_fast16_t`.
              - Use separators to make numbers easier to read `10'000` instead of `10000`
              - Line 43-55, 58-68: Duplicate code
              - Don't bind references to fundamental types. Copying them is faster.
              - Use `std::accumulate` or `std::reduce` to calculate the sum of all elements in a container.

              `std::array` is a wrapper around a C-style array. It is as fast as a C-style array. If you don't know the size of an array at compile-time, use a `std::vector` or, if you know the maximum size and it's small, write a container that wraps a `std::array` and keeps track of the number of used elements. You never need C-style arrays, don't use them, they're dangerous.

              Good to know that my avatar is recognizable, I was worried it looked too much like a bear with a mustache and mexican hat

              • choofe

                Hi. Me again!
                change to a unsigned int instead of bool.
                Now I'm thinking I'm obsessed with std::uint_fast16_t.
                is that alright or that is too much?
                also lesson 4.6 has stated that "C++ officially adopted these fixed-width integers as part of C++11. They can be accessed by including the cstdint header, where they are defined inside the std namespace."
                But I didn't include that header. Is it included by default or something? Or it is included in one of other header I've used

                • nascardriver

                  You still have duplicate code in line 7-10 and 15-19 and the duplicate calculation `number / 10`. Also, don't use signed types for bitwise operations. Their most significant bit has a special meaning, which you don't want. You just want to store bits, so use an unsigned type. Here's how you could write this function without code duplication

                  Note that in the original fast solution, they are using

                  If `rdig` is 0, this code causes undefined behavior (At least in C++, I don't know about C), because they're trying to left-shift 1 by -1.

  • goiu

    I've read in one of the comments of this lesson that there is a reddit discussion which claimed that isn't good to learn c++ from this site.
    Well, after finishing this, i would say: are we talking about the same thing? o.O
    BEST TUTORIAL EVER, not only for c++, but also for programming in general.
    I've studied c programming at high school in Italy (i'm italian, sorry for my bad english xD), but wasn't teached at this level and deepth.
    I've been frustrated for a long time because i've followed so many tutorials online that i started thinking that the problem were i, that i'm not smart enough for programming etc.
    But this IS the only site that keept me motivated to study, to go further, to be curious, and now, i'll definetly take a decisive step toward the goal of becoming a real programmer and actually programming!
    Thanks you very much, to Alex and Nascardriver: even if i dind't asked many questions, i've felt every answer to a learner as it was addresed to me, to my doubts, it's a strange feel, but i'm so grateful for you work.
    Just a note: i didn't enjoyed the last chapters from the 16 as the previuos ones, because are like just a list of things, little contextualised and more in a referenced-style, of course explained better tha references sites, but i think that this is a little bit inconsistent with the rest of the tutorial.
    I've just one doubt: in order to become seriously a programmer, it is required to study advanced maths?
    To give you some context, i am interested in cyber security, but for this there i will attend a master from the next year, so i'm more concerned to self-learn ai, machine-learning and networking
    Again, thank you and keep up the amazing work!

    • nascardriver

      Hi! Glad you enjoyed it :)

      I noticed the same thing with chapter 16 onward. I think it's best to remove these chapters and incorporate the important parts into other lessons.

      Not all programmers need math, cyber security needs math. You'll be dealing with encryption, and that's pretty much pure math. That doesn't mean you need to start studying math like crazy. Start reading about cyber security and then learn what you need.

  • choofe

    Hi Nascardriver.(I'm back)
    I have no idea where to ask my questions as they are very general and have different topics.
    I wonder if you can make a page or so just for asking questions in general. I tried stackoverflow but there are many different opinion on a topic and that'll cause more confusion!
    any way I've found this website that has many problem(most math) which are best to be solved by programming(any language). The base work is algorithm though but in implementation phase there are confusions. this website has a comment page for each of problem which people who solved that problem can discuss(more likely to explain their algorithm and their codes)
    In some of these problems I successfully had solved the problem but when I checked the other people's solutions I've found my solution takes more time than theirs(I'm talking about 3.5 seconds vs 0.01 second)In almost identical algorithm.
    So is there a way we can discuss where is the problem? and how this could happen? I know you are an enthusiastic and free dedicator so I have no expectation.
    Thanks again for so many things I've learnt here.

    • nascardriver

      Hi!

      You can post such question in the lesson that fits to code best, or in a lesson that isn't about programming (Such as this one).
      Can you share a link to the 2 solutions or post them here?

      • choofe

        Thanks for response dear nascardriver who isn't a nascardriver . I will post my solution to one of the problems and one that took about 400 times faster than mine! I feel like an idiot.
        the problem also is in my solutions comments
        I don't know if this is a good idea to discuss this solutions as they are almost big codes (in scale of this post's comment area). It's your call.
        I appreciate if you give me hints to improve the code or totally change my style(because I'm doubting if I'm doing it wrong at all)

  • ammawn

    Thank you for the tutorial! Is there somewhere that I can check for future updates or changes to any of the pages?

  • sv

    this is the best free c++ tutorials in the internet, believe me i have searched a lot
    thank you Alex and Nascardriver!

    could you guys add a small chapter on makefiles? i know its a very extensive topic, i am just asking for introduction without using any big and confusing words...

    • nascardriver

      Notes, thanks for the suggestion!

      I can't recommend using Makefiles directly. Instead use CMake to generate Makefiles for you. That way you get compiler- and platform-independent projects and configuration.

  • I_wanna_know

    Is the nascardriver really a Nascar Driver?

  • Nay Oo Lwin

    Thanks alot for making my covid-19 quarantine period enjoyable.

  • koe

    Got to the end! :) around 8 months after I started (with a ~3 month break), thanks a bunch Alex and nascardriver

  • Xeb

    Alright Nascar Driver bitch, i did it.

    Thanks for the tutorials, send me the bill, i will pay you.

  • Amir

    Thank you Nascardriver thank you Alex . I think i'll not stop coming here and reading more and more , it's a best place i ever seen introduce real learning, my English not that good enough to express how really I feel thankful your efforts , special thanks for you Nascardriver for all notes you gave to me :)

  • Martin

    I really think your C++ tutorial is one of the best, of not the best, out there.

    Will there be an update for C++20 anytime soon?

    • nascardriver

      Thanks :)
      C++20 features are gradually being added to the existing lessons. We can't add content that we haven't used ourselves, so it takes time until we become familiar enough with the new features to write about them and answer questions. Is there anything in specific you'd like to be added?

      • Martin

        I would love to see a lesson on the new modules and when to use them.

        • nascardriver

          Ah yes, modules. They'll have a big impact once they're available. As of now, no compiler has support for modules and I'm afraid it will be quite a while until they're readily available.
          Once they're there, modules will be replacing the #include lesson, leaving #includes as a note to the past.

  • ppastram

    Thank you very much for this amazing course! I learned a lot while having fun. Incredible explanations.

  • Maulik

    Thank you very  much for the wonderful course! I learned a lot with these code snippets and superb explanation! Amazing work! Can you suggest similar work on unit testing or next steps for small C++ projects to improve knowledge upon?
    Again, many many thanks.

  • Mustansir

    Hi Alex,

    I am an experienced C++ programmer working on legacy applications using C++03. I wanted to update myself to learn C++11/14 for which I went through your tutorials. I found them very good on clearing the concepts where many other resources I referred confused me. I really liked your style of teaching building the concepts step by step.

    I would request you to point us to some good resources to learning Network Programming and Multithreading (if you have some tutorials on them, nothing like it!!).

    Thanks,
    Mustansir

  • Mohammad Riyan

    My string view option doesn't work? How do I get a c++20 compiler?

  • Mohammad Riyan

    Do you have any other websites for learning c programming language or html or anything like these?

  • Gabriel

    Hi Nascardriver and Alex!
    I finished all tutorials from your site and I want to ask you if is ok to start with Unreal Engine 4 or what I need to know before I start with it.
    At the same time I will continue with cppreference and more.
    I hope you can answer me. (sorry for my bad english)

  • Tom

    Brilliant, thanks very much for this great tutorial.
    I last programmed C++ in 1995 - it's come on a bit :)

  • choofe

    Hi Nascardriver again!
    You mentioned a CMakeLists.txt.
    I went through microsoft Cmake section and it was all
    about creating a project from scratch.And more likely to create cross platform apps.
    How can I create that listfile for my existing project (solution)? I also searched other places and nothing to do so. I even ended up to download Cmake GUI 3.17 but honestly didn't figure that out!
    however I uploaded other files in the directory to repo.
    they didn't contain my preferences on language standard!-

    And something else about the review of my program:
    I needed a constructor of a class to do a certain job (fill with zeros) it doesn't need any parameter to do so! In the other hand I also have another constructor with no parameter that does another job (fill random numbers) it is as follows:

    and this one does another job:

    is there any standard or a conventional way to address this issue?
    because I overload the constructor with a random useless parameter type in the context, the one I would never need to use. Here it was a bool:

    • nascardriver

      Here's a very minimal CMakeLists.txt, assuming that your files are in a "src" directory

      I don't know if VS has builtin support for CMake and I don't know how to invoke CMake on Windows, you'll have to look up instructions for that.
      The sudoku.vcxproj sudoku.sln files are what contain your project settings (I don't know if they're both required). Now other people can open your project in VS. People with other IDEs still have to compile it manually, this wouldn't be the case with CMake, but Windows projects often don't support anything apart from VS.

      > I needed a constructor
      You can't have multiple functions with the same signature. The caller wouldn't be able to differentiate them. You can add a parameter to your constructor and fill the block based on that

      And possibly add a default argument to the constructor if you want to.

      If you don't want to merge the constructors into one, you can keep them apart and add useless parameters like you did. Then add static member functions to `Block` that call those constructors so the user of your code doesn't have to care about the parameters.

      To prevent having weird parameters, you can add custom types and use those

  • choofe

    Hi nascardriver and alex
    I have written a little program which solve a given board of sudoko (it can produce an initial one too. it may be unsolvable and program will tell)
    I uploaded it in gitHub. I wonder if you have enough time to check that out and point me my bad! (or good I hope)
    I learned all I know about c++ from this site.
    I didn't know anything at all before so this program is what I learned from you.
    https://github.com/choofe/sudoko.git

    • nascardriver

      Hi!

      I can't look at everything, but here's a quick review:

      - You didn't push any files that allow compilation of your code. Anyone who wants to compile your code has to set up a project themselves and guess which compiler settings are required. If you're using VS, push your project files. If you're using a good OS, push the file that you're using to compile your code or to generate a build script (Most often CMakeLists.txt).
      - File naming is consistent, nice. As always, avoid abbreviations. Is that GridColor or GridColumn? Only you know. And in 3 month, you'll have forgotten too. Same goes for your variable names. `b`allon, `pos`ture, `num`eric, etc. aren't very descriptive.
      - Use single quotes for characters. Double quotes are for strings.
      - `size_t` is C, `std::size_t` is C++.
      - Magic numbers. Use constants or get the values dynamically, eg. `grid.size()` is you have something like that.
      - There are spell-checker plugins that work in code.
      - Use your auto-formatter.
      - main.cpp:65 should probably be a reference.
      - You shouldn't need so many indexes in `Position`. If you know the size of your field, you can calculate everything based on `m_index` (If that's the index into the big array).
      - Empty destructors
      - #pragma once and manual header guard. The #pragma once is never used because of your manual guard, and it prevents compilation of compilers that don't support it. If your IDE adds #pragma once when you create new files, disable that.
      - In the loop in `GridCollar::gridCollegeCheck`, you don't need the index for anything. Use a standard algorithm or a range-based for-loop.
      - `GridColumbia::m_gridCola`: You know the size, this should be `std::array`.
      - You only need 1 header guard per header. Looking at BOARD_T_H and BOARDVEC_T_H.
      - Copy initialization.
      - Missing includes.

      Good classes, good operators, good const, good documentation, good job :)

      • choofe

        Hi thanks for the review.

        I GET it! I'm lazy at naming variables (I tried my best but sometimes it is a pain in the head!.)
        I'm very unfamiliar with gitHub and its aspects.
        most of the works in this program is for exercising. and implement what I learned so far.I tried to do everything at least once, like header guards.
        I had a very confusing times with those range based loops so I turn into classic ones.

        And some of the above I have question:
        what do you mean by line 65 in main.cpp be a reference?
        >> `size_t` is C, `std::size_t` is C++. what is the difference? I mean is std::size_t has something in particular to prefer it to size_t?
        >> Empty destructors : what harm is in those? I have no dynamically allocated member in any class.
        >>You know the size, this should be `std::array`. Is std::array faster than std::vector? because sometimes it goes like it is in infinite loop and I'm counting how many check have been done and it was as high as 4 million times. I am almost certain that the algorithm is consistent! but the amount of check that is done makes me doubt the algorithm!
        and Last but not least:
        >>Good classes, good operators, good const, good documentation, good job :)
        I assume myself a student of Alex and you.if it doesn't bother you.(that is what I learned is what I learned here.)
        and of course the "GOOD JOB" is actually to you :)
        P.S corrected as much correction you reviewed as I could and will push it to github to a branch named corrected.

        • nascardriver

          > line 65 in main.cpp be a reference

          You're creating a copy of the grid by doing this. You probably don't want to create a copy, but work with the original grid

          > `size_t` is C, `std::size_t` is C++
          They're the same thing, but one is in the `std` namespace and the other isn't. The non-std variables and functions exist because some headers are compatible with C. If some other library also declares a `size_t` without a namespace, you'll run into name conflicts.

          > Empty destructors
          There's no reason to have them. They don't do anything, so you might as well remove them to avoid confusion. If I see a user-provided destructor, I assume that there's some special cleanup happening. You said it yourself, you're lazy, so why spent time writing something that does nothing?

          > Is std::array faster than std::vector?
          `std::array` is faster and safer than `std::vector`, because it doesn't do dynamic allocations and has a known size. I don't understand what you said after that. Where is an infinite loop?

          • choofe

            As you mentioned I am lazy and those destructors was automatically created by IDE (VS) so I had to remove them by myself and that was against the laziness :). But if it makes a difference I will clean them all.

            bonbon?
            OK then I get it
            I will never ever use non descriptive variable
            I learned my lesson
            I went through all the codes and rename what was non descriptive. :)
            >>about infinite loop:
            sometimes I get result in a reasonable time (say 7-8 second -I got a 2.8Ghz cpu)
            but sometimes it goes on and on without any result or error! the checking repeats for 4 million times as I end the execution!
            Is it worth a shot to implement std::array instead of vector? to see if it give me a result on those long no result executions?

            • nascardriver

              Those infinite loops aren't caused by vectors. This sounds like a bug in your solving algorithm.
              I haven't seen your entire code, but if you've used the vector correctly, you shouldn't notice a difference when you change the board type. You might notice a difference when you change the return types of your getRow and getColumbian functions (I don't remember the real names), because those probably get called very often.

  • Anonymous

    Thank you for helping me out!

  • n33rj

    Hello there!
    I have learned C++. I know how to program C++. This website taught me a lot about C++ language. But language is not the only thing in software development. There are other tools that are used while programming like version control(git), unit testing, performance profiling, build systems, continuous integration and many more that i am probably not aware of.

    Can you suggest some resources where i can learn these advanced concepts of software development? It can be books, websites or anything.

    Sorry if this is a bit off topic. :)

  • Cihan Ulas

    Excellent work. Very thanks.

  • strees

    Thank you Alex and Nascardriver!!! Just finished going through all of these and just wanted to express my gratitude for all the work you've put into these wonderful and in-depth tutorials thank you thank you

Leave a Comment

Put all code inside code tags: [code]your code here[/code]