error: expected initializer before "int"
I'm following the OpenGL SuperBible 4th edition.
I'm using Xcode and created a project in foundation tools, c++.
I've written some simple code but I get an error: expected initializer before "int" when i try to compile and since i'm new to this, I can't figure out what the problem is.
Here's a snippet of the code:
void main(void)
int main(int argc, char * const argv[]);
X error: expected initializer before "int"
help =X
I'm using Xcode and created a project in foundation tools, c++.
I've written some simple code but I get an error: expected initializer before "int" when i try to compile and since i'm new to this, I can't figure out what the problem is.
Here's a snippet of the code:
void main(void)
int main(int argc, char * const argv[]);
X error: expected initializer before "int"
help =X
You've declared main() twice. Remove the "void main(void)".
You also shouldn't be declaring a prototype for main(), which is what this appears to be since there's a semicolon at the end of the second one. When you do put a main function in your code, the second prototype is correct. Like this:
By the way, when you want to paste code hit the "#" button above the message field to enter CODE tags.
You also shouldn't be declaring a prototype for main(), which is what this appears to be since there's a semicolon at the end of the second one. When you do put a main function in your code, the second prototype is correct. Like this:
Code:
int main(int argc, char **argv)
{
//your code here
}
oh, i didnt mean to put the semicolon.
The book i'm reading has the void main(void) right above this code.
When i get rid of one (void main(void)) it still gets an error.
Code:
int main(int argc, char * const argc[])
{
// code
}The book i'm reading has the void main(void) right above this code.
When i get rid of one (void main(void)) it still gets an error.
Quote:error: expected initializer before "int"This suggests something is wrong before the "int". Look at the lines above. If there isn't any code above in the C file, look at the headers you've included - a typo in a file you wrote could cause this. Alternatively, including a C++ or Objective-C header in a C file (for example) will confuse the compiler, although in that instance I'd expect loads of errors.
If you still can't work it out, paste the whole file into this thread.

