struct MyStruct {
int x;
};
MyStruct theVar;
theVar.x = 10;
int main() {
return 0;
}
Why is the compiler giving me the error:
error: ‘theVar’ does not name a type
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can only create variables and initialize them outside
mainat the global scope. You cannot assign to variables at global scope like that.You have two options:
Initialize it at time of creation:
Or
Assign it in
main:Note that first approach is better as it just has one step, Initialization, Second has two steps Initialization and Assignment.