When using const members in your class you have to construct them in a initializer list. But in which order should you construct them ? I created a example where the order actually matters — we need Cylinders first before we can construct a Car’s engine. But the following code holds a nasty bug. Can you spot it ?
struct Engine{
std::vector<std::string> cylinders;
};class Car{
public:
const Engine mEngine;
const std::vector<std::string> mCylinders;
Car(std::vector<std::string> cylinders):
mCylinders(cylinders),mEngine(mCylinders){}
};
Here is an basic main() function that constructs a Car and then prints all cylinders in the car’s engine:
int main()
{…If you write native code for Android you probably declared
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "TAG", __VA_ARGS__)somewhere in a header file. Almost every ndk example project from Google uses this line. And for smaller projects this is totally sufficient.
However, the more logging you do inside your project the more annoying this one-liner can be. First, you cannot re-define this macro easily with a custom TAG inside a new class header. And second, you cannot use c++ — style logging with it. Anything like `std::cerr << “Error message\n”; ` must be either written into a temporary `std::stringstream` or translated into old c-style…
