#include <iostream> using namespace std; class foo{public: foo() { test = 2; } int get() { return test; }private: const int test;}; int main(){ foo f; cout<<f.get(); return 0;}
Standard input is empty
prog.cpp: In constructor ‘foo::foo()’: prog.cpp:8:5: error: uninitialized member ‘foo::test’ with ‘const’ type ‘const int’ [-fpermissive] prog.cpp:10:16: error: assignment of read-only member ‘foo::test’
Standard output is empty
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!