In C++, the only technical difference between a struct and a class is that, by default (i.e., if you don’t specify anything), members of struct are public while members of a class are private. You can achieve encapsulation in a …
Read moreCan I return more than one thing from a C or C++ function?
Yes. Whether or not a function can return more than one value depends on the specific programming language you’re using and on whether you’re talking about pure functions or impure functions. Many programming languages, including C and C++, chose the traditional mathematical …
Read moreWhat is the third parameter I sometimes see defined in the main function?
The third parameter to the main function is not standard or portable in C or C++, but in practice, most modern compiler implementations allow an optional third parameter to main. The data type of this third parameter is pointer to …
Read moreWhy don’t they add a garbage collector to new versions of C and C++?
Let’s start by considering C++. As an opt-in option in C++, it is technically possible to add garbage collection to C++, as long as it is clearly specified how it integrates with the language and with the existing memory management …
Read moreWhat would happen if a bitwise operator like ^ were applied to objects of a C++ user-defined class?
The behavior depends on what conversions and operator overloads are defined for these types of objects. To simplify the discussion, let’s say that the objects you’re talking about are instances of class X. According to the C++ standard, bitwise operators …
Read moreWhy do people still use Python, C, C++, C#, and Java when there is Go?
I know and use several programming languages in my software and firmware development projects. There is a core set that I use most often, because they happen to be the right tools for the job. Early on, I learned several …
Read moreWill a game engine in Python be slower than one written in C++?
If we assume that: The Python programmers are highly competent, and The C++ programmers are highly competent, and Python is interpreted, and C++ compiles to native (machine) code, and has typical optimizations enabled in the compiler, and There is no …
Read moreFriend Classes in C++
I get quite a few questions about when or whether it’s a good idea to declare friend classes in C++. Here is some background and advice on the use of friend classes. Recall that members of a class that are …
Read moreKeeping the Console Window Open in Visual Studio 2017
Starting with version 15.8.0 of Visual Studio 2017, which was released August 14, 2018, you have a new option for controlling whether the console window closes automatically when your C and C++ console-based application terminates, and what information you see …
Read moreDisabling warnings from legacy and third-party header files
I am a huge fan of warnings in C and C++. I have always taken warnings from the compiler seriously, and tell my students to get used to taking them seriously, too. Warnings are the compiler’s way of telling you: …
Read more