Hi there
I am just starting out in programming and using Both the internet and books to learn C++
this code is direct from book. I am getting the error
expected unqualified-id before '{' token
on lines 32,38,44 these i have marked /////////this is first error
I am using code::blocks mingGW 64 bit
I have searched the net and your forum and only found ;after the main () I don't have this
any suggestions please
just remove the semicolons after access_global), hide_global(), and change_global(). With semicolon it's a declaration and the compiler doesn't expect a function body
//Global reach
//Demonstrates global variables
#include <iostream>
usingnamespace std;
int glob = 10; // global variable
// Recommend capitalizing when you make something global. That defines it being Global Scope.
// Just a naming convention. Not a Rule.
void access_global();
void hide_global();
void change_global();
int main()
{
cout << "\t*****GLOBAL REACH*****\n\n";
cout << "In main() glob is: " << glob << "\n\n";
access_global();
hide_global();
cout << "In main() glob is : " << glob << "\n\n";
change_global();
cout << "In main() glob is : " << glob << "\n\n";
return 0;
}
// FIXES MOSTLY BELOW THIS LINE
void access_global() // Bad semicolons after function names
{
cout << "In access_global() glob is: " << glob << "\n\n"; // You forgot a "<<" after "glob"
}
void hide_global()
{
// Redefined a new glob. BAD.
// Guessing this was on purpose
int glob = 0;
cout << "In hide_global() glob is: " << glob << "\n\n"; // You forgot a "<<" after "glob"
}
void change_global()
{
glob = -10; // This was a check if glob is equal to -10. Not assignment. Removed one "=".
// Forgot a semicolon in previous line.
cout << "In change_global() glob is: " << glob << "\n\n"; // You forgot a "<<" after "glob"
}
as i said that code was directly from book , not a great deal of info on global variable in the chapter
Going to have to get some more books in this early stage
thanks once again
Im guessing I got a long way to go with this language lol