test heythere(5);
main.cpp: 31: 19: error: expected identifier before numeric constant
main.cpp: 31: 19: error: expected ',' or '...' before numeric constant
If you initialize the field directly in the class body, you must use either = … or {…} .
(…) - it is impossible. This is probably because in such a case it becomes too difficult for the compiler to distinguish the declaration of the field with the initializer from the declaration of the method (where the brackets would be a list of parameters).
Even the name of such an initializer in the grammar of the language hints at this: brace-or-equal-initializer .
One of the following options will suit your choice:
test heythere = 5; test heythere = test(5); test heythere{5}; test heythere = {5}; test heythere = test{5};
Specifically, in this case, all five behave in exactly the same way, but in general there is a difference between them. Read more here: https://en.cppreference.com/w/cpp/language/initialization
Another option: Leave only test heythere; , and perform initialization in the initialization list in the constructor: rage() : heythere(5) {...} . (Either : heythere{5} .)