Computing.Net > Forums > Programming > Please help C++ Functions

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.

Please help C++ Functions

Reply to Message Icon

Name: stbede77
Date: September 2, 2004 at 14:11:27 Pacific
OS: XP Pro
CPU/Ram: 2.8 ghz with 1024ram
Comment:

I just got the newer virsion of microsoft visual c++ 6.0 and now I am haveing problems with all of my functions. I wrote the simple function below to see what is going on. Even with it I get an error that says "C:\Program Files\Microsoft Visual Studio\MyProjects\test2\test2.cpp(10) : error C2447: missing function header (old-style formal list?)". Sorry if this is a dumb question but I haven't run into this error in the past and cant find info how to get rid of it.

#include <iostream>
void d();
void main()
{
d();
return;
}
void d();
{
cout << "HI";

}




Sponsored Link
Ads by Google

Response Number 1
Name: Rolos
Date: September 2, 2004 at 15:36:55 Pacific
Reply:

I can see one problem here. You have a semicolon on line 8 after your function name where you're trying to define it. Also you might want to add using namespace std; before your main() function.

- Rolos


0

Response Number 2
Name: Don Arnett
Date: September 2, 2004 at 15:39:47 Pacific
Reply:

1 - a definite problem is the semi-colon in your function declaration:

void d(); <--- should not be a ; here
{
..
}

2 - I would expect your program to compile after fixing #1, but MSVC may be pickier about things than you are used to. So you may get warnings about not declaring parameters for your function.

#include <iostream>
void d(void);

int main(int argc, char **argv)
{
d();
return 0;
}

void d(void)
{
cout << "HI";
}


Putting void as the parameter in the prototype and the function declaration, tells the compiler that no parameters are allowed. This allows the compiler to check for you that function calls have the proper parameters and types. Note that when you call the function, you don't use the void. Declaring the function as d(), tells the compiler that you aren't telling it what parameters are required. When you do this, the compiler can't check parameters and types.


0

Sponsored Link
Ads by Google
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: Please help C++ Functions

help help!!!..C...data file..please www.computing.net/answers/programming/help-helpcdata-fileplease/8092.html

So confused about C functions.. www.computing.net/answers/programming/so-confused-about-c-functions/7040.html

C functions www.computing.net/answers/programming/c-functions/8690.html