On 12/10/2022 11:06, Mark wrote:
> I have this tiny eg:
> ```cpp
> // g++ -o t t.cpp && ./t
<snip>
>
> What am I doing wrong?
You forgot the critical compiler flags:
g++ -Wall -Wextra -O2 -o t t.cpp
Running your compiler without warnings enabled is like driving without
seatbelts and airbags - you might be lucky, but there might be a mess
that is hard to identify. Running it without optimisation is like
driving when stuck in first gear. C++ is not designed to be used
without optimising compilers. Use at least -O1 to inline all the "no
code generation" functions that abound in C++, and to enable analysis
for static error checking.
Compiling the Error class with -Wall -Wextra gives
<source>: In constructor 'Error::Error(const char*)':
<source>:5:5: warning: 'Error::message_' is initialized with itself
[-Winit-self]
5 | Error(const char* message) : message_(message_) {}
| ^~~~~
<source>:5:23: warning: unused parameter 'message' [-Wunused-parameter]
5 | Error(const char* message) : message_(message_) {}
| ~~~~~~~~~~~~^~~~~~~
Compiler returned: 0
The tools are there to help, and would have given you the answer
immediately. (But then we'd have missed this Usenet thread!)