error C2448: function-style ini..

June 12, 2009 at 05:27:17
Specs: Windows Vista
I am writing a code for a college project but i kept
getting this error within it so i tried to resolve it in a
separate program but i still can not resolve it.


This is the error appearing... 1.cpp(38) : error C2448:
'validate' : function-style initializer appears to be a
function definition

could you please help.


#include<stdio.h>
#include<process.h>


void getinforamtion(void);

int i;


bool bok;
bool validate;
int date;
void getinforamtion(void)
{

do{
printf("\nEnter a number");
scanf_s("%d",&date);
printf("%d",date);
if(validate == false)
{
bok = false;
}

else if(validate == true)

{
bok = true;
}

}while (bok == false);


}

bool validate(bok = false)
{
if(i == 2)
{
return true;

}
else
{
return false;
}
}

void main (void)
{
getinforamtion();

}


Thanks alot



See More: error C2448: function-style ini..

Report •


#1
June 12, 2009 at 15:44:24
You are getting the error because you have already declared
'validate' as a simple variable:

bool validate;

but then you try to define it as a function:

bool validate(bok = false)

First, the signature is incorrect, it should be

bool validate(bool bok = false)

Secondly, you can't have the same identifier be both a
variable and a function in the same scope. Most probably
what you wanted to do was declare it as a function instead of
a variable, in which case either define it before the point of first
use, or have a forward declaration:

bool validate(bool bok = false);

Here are some further general comments on your code:

#include<process.h>


You don't appear to be using this header in the rest of your
code.

scanf_s("%d",&date);

This is a Microsoft-specific extension. You shouldn't use it if
you need to write Standard C or C++ code.

if(validate == false)

Experienced programmers don't write it like that, they write

if (!validate)
.

if(validate == false)
{
bok = false;
}
else if(validate == true)
{
bok = true;
}

That is the same as

bok = validate;

Why say it in 10 lines when you can say it in one?

Having said all that, I think what you meant was to call
validate(), not validate.

if(i == 2)
{
return true;

}
else 
{
return false;
}

Just say it in one line:

return (i == 2);

Much clearer, isn't it?

void main (void)

That's not standard C or C++, in both languages main returns
int, not void. Also, there's no need to put void in the argument
list, just use ().


Report •
Related Solutions


Ask Question