C++ Coding help Needed
-
I have this one line in my C++ code that I'm using, but it says I need a initializer before the word "main". I took C++ a couple of years ago, so I naturally forgot what an initializer is, but I'm pretty sure that it's not int. Can anybody help? Code: int __cdecl main(int argc, const char* argv[]) {
-
I have this one line in my C++ code that I'm using, but it says I need a initializer before the word "main". I took C++ a couple of years ago, so I naturally forgot what an initializer is, but I'm pretty sure that it's not int. Can anybody help? Code: int __cdecl main(int argc, const char* argv[]) {
Y u've mentioned __cdecl? Its implicit and return some value.
-
I have this one line in my C++ code that I'm using, but it says I need a initializer before the word "main". I took C++ a couple of years ago, so I naturally forgot what an initializer is, but I'm pretty sure that it's not int. Can anybody help? Code: int __cdecl main(int argc, const char* argv[]) {
waiwai933 wrote:
so I naturally forgot what an initializer is,
May be true :) , AFAIK initializers are for data types not for function, which gives initial values to variables.
waiwai933 wrote:
but I'm pretty sure that it's not int.
iam not sure couple of years ago it was so. :) return of main is same as calling exit function in main, it is used to return the success code of the application and it is int. u can avoid returning any value if the type of main is void. As a side note C++ doesnot assume default int for function return type (may be this is ur "pretty sure"). u can check whether main is using int by giving return type like double (where sizeof(return type) > sizeof (int) or user type)
waiwai933 wrote:
this one line in my C++ code
In this line of C++ code, i think no issues. can u state what is the exact error statement.
waiwai933 wrote:
Can anybody help?
I suspect some code above or below this function causing the error say
struct MyStruct
{
} // missing ;
int __cdecl main(int argc, const char* argv[])
{in this case compiler says error in return type as it takes MyStruct as return type.
-
I have this one line in my C++ code that I'm using, but it says I need a initializer before the word "main". I took C++ a couple of years ago, so I naturally forgot what an initializer is, but I'm pretty sure that it's not int. Can anybody help? Code: int __cdecl main(int argc, const char* argv[]) {
Unless you are passing arguments to
main()
and are returning a value to the command interpreter, you could simplify things by using:void main( void )
{
...
}"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne