Hi!
I'm learning C++ programming. I got a problem with simple class.
Here is the code:
Code:#include <iostream> using namespace std; class Menu { int NUMMENUS = 0; char* labels [NUMMENUS]; bool selected[NUMMENUS]; public: void Setnum (int i) { NUMMENUS = i; }; int Getnum() { return NUMMENUS; }; }; int main(void) { Menu menu; menu.Setnum(8); cout<<"Number on: "<<menu.Getnum()<<"\n"; return 0; }
And here is the error:
Where is the error?Code:leho@leho-laptop:~/Dokumendid/OpenGL/Menüü$ g++ teine.cpp -o teine teine.cpp:8:18: error: invalid use of non-static data member ‘Menu::NUMMENUS’ char* labels [NUMMENUS]; ^~~~~~~~ teine.cpp:7:17: note: declared here int NUMMENUS = 0; ^ teine.cpp:9:18: error: invalid use of non-static data member ‘Menu::NUMMENUS’ bool selected[NUMMENUS]; ^~~~~~~~ teine.cpp:7:17: note: declared here int NUMMENUS = 0; ^
Leho