The C++ Programming Language (2021-07-12 - 2021-07-16)¶
Question: so I could store the address of an integer in an integer?
Answer: the C compiler would let you (if he’s nice he can issue a warning), but this is not what you want. Because you’d lose half of the 64-bit pointer value when you store it in a (32-bit) integer.
Group project review¶
On Github, there is a directory OO-Point. Starting
point implementation, write comparable classes
circle, containing a method
rect, also containing a method
sphere(in 2D :-) ), also containing a method
Make the associated test programs run:
Preprocessor, to clear up Julia’s include guard question. Sigh.
Constructor, Destructor, Copy
Functions and Methods
Current state is, we’re writing one program to test one aspect/requirement. This is something that can be formalized (/me big fan of things that are so simple).
Install Google’s unittesting framework (on Doze, sadly), and start to use it.
Clone GitHub repository:
$ git clone https://github.com/google/googletest.git
Build with VS Code: open directory, and hit CMake build botton
Build by hand
$ cd googletest $ cmake .
lib/*.ato MinGW installation
include/gtest/to MinGW installation
Central workflow. Much like SVN’s, except that local commits are possible.
Distributed workflow. (At least, one possibility). Resembles Github “pull requests”.
References recap (References)
explicit: another C++ trap/bug (automatic conversion), fixed by an ad-hoc solution - the
explicitkeyword, bolted onto what’s there. Here’s a live-hacked explanation of it.
It has gotten a bit larger becauser I used it as an introduction to recource management and smart pointers.
Pointer classes (“smart pointers”)
std::unique_ptr<>is the simpler of the two in what it does, its usage is more involved. Ownership transfer (this is what I like about it) is implemented using the outright genius “move” mechanism (since C++11), and one needs to know a bit when the compiler fails to enforce the ownership transfer contract.
Live-hacked that here.
Didn’t go through it in great detail (time was over anyway). Shared ownership, though, is easier explained than unique ownership: “just don’t think about it”. (Should have mentioned reference cycles, to make things more complicated :-) ).