> The code compiles without errors or warnings but when I run it I get segmentation fault.
> My compiler is g++(GCC).
Ask g++ to compile the code as standard C++ (
-std=c++14 -pedantic-errors ); it does not do so by default.
Also turn on all warnings (
-Wall -Wextra )
1 2 3 4 5 6
|
// -g++ -std=c++14 -Wall -Wextra -pedantic-errors
// ***error: too few arguments to function 'int Gtk::Application::create(int, char**)'
// decltype(Gtk::Application::create()) _app;
// (assuming that there is no nullary overload of Gtk::Application::create)
decltype( Gtk::Application::create( 0, nullptr ) ) _app ; // should be fine
|
> when I run it I get segmentation fault.
> I think it has to do with my use of decltype and assigning to that private member variable.
This particular Linuxism, though ugly, may not be the cause of the segfault. ** EDIT ** well
Compile with
-std=c++14 -Wall -Wextra -pedantic-errors and see if there are other errors/warnings.
> Why does this work but putting it in the constructor body does not?
As far as C++ is concerned, in either case, it is an error; the program is ill-formed; an error diagnostic should have been issued.