Computing.Net > Forums > Programming > error C2448: function-style ini..

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

error C2448: function-style ini..

Reply to Message Icon

Name: Asim91
Date: June 12, 2009 at 05:27:17 Pacific
OS: Windows Vista
Subcategory: C/C++
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: June 12, 2009 at 15:44:24 Pacific
Reply:

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 ().


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: error C2448: function-style ini..

error C2448: '' : function www.computing.net/answers/programming/error-c2448-function/10830.html

Error message C++ www.computing.net/answers/programming/error-message-c/14103.html

Compile error C++ www.computing.net/answers/programming/compile-error-c/11983.html