Why does sololearn complier post and error here? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does sololearn complier post and error here?

It says that there is an unqualified Id before ‘void’ in ShowX::void SetX(int y) Here is the snap bit of code: The full code is here: https://code.sololearn.com/cNA9f1f3kxO6/#cpp #include <iostream> using namespace std; class ShowX // class function { public: int GetX(){return x;} void SetX(int y); protected: int x; // we have to use the functions above to use x }; ShowX::void SetX(int y) { if(y < 0) { //the pointer throw throw new string "Sorry, the value of X was smaller than 0, causing an Exception :(\n"; } else if (y > 100) { //the value throw throw y; } else { x = y; } } I don't understand :|

15th Oct 2016, 8:07 PM
smileyface
smileyface - avatar
2 Answers
+ 1
Change following, ShowX::void SetX(int y) as follows, void ShowX::SetX(int y) I've also noticed two missing semicolons.
16th Oct 2016, 6:22 AM
Sumudu
Sumudu - avatar
0
It seems after 4 days you managed to solve the problem but the errors were : 1 - Line 14 : return type comes first and before function namespace or method class namespace. 14 : void ShowX::SetX(int y) 2 - Line 19 : Parenthesis around the string : 19: throw new string("Sorry, the value of X was smaller than 0, causing an Exception :(\n"); string is a constructor and ctors are also functions so they need parenthesis. 3 - Line 38 : missing semicolon after function call try {myX.SetX(z);} // try the setx function 4 - Line 45: missing semicolon end of the line cout << "The value of x is bigger than 100, causing an exception. :(";
19th Oct 2016, 10:35 PM
TwinChrist