error C2447: '{' : missing function header (old-style formal l

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 9290 Views - Last Post: 06 May 2008 - 10:36 AM Rate Topic: -----

#1 KMH  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 80
  • Joined: 23-March 08

error C2447: '{' : missing function header (old-style formal l

Post icon  Posted 05 May 2008 - 05:42 PM

Guys, I have this code that was working, but when I moved the function to header and other to main and fucntioncall, it has compiler error [error] error C2447: '{' : missing function header (old-style formal list?)[error]

This is the function header file
 
//Function proto type
bool wrap(float paper_w, float paper_l, float box_l, float box_w, float box_h);




This is main file

#include <iostream>
#include <cmath>
#include "WrapFunction.h"

using namespace std;
//Function proto type
int main()
{
			float box_l = 0;
			float box_w = 0;
			float box_h = 0;
			float paper_w = 0;
			float paper_l = 0;
			cout << "Enter the box length in inches: ";
			cin >> box_l;
			cout << "Enter the box width in inches: ";
			cin >> box_w;
			cout << "Enter the box heigth in inches: ";
			cin >> box_h;
			cout << "Enter the wrapping paper width in inches: ";
			cin >> paper_w;
			cout << "Enter the wrapping paper length in inches: ";
			cin >> paper_l;
			cin.get();
			
			
cin.get();
return 0;

}




This is FunctionCall

#include <iostream>
#include <cmath>
//Function proto type
#include "WrapFunction.h"

using namespace std;
{	
			   {
				if(box_l + box_l + box_h + box_h > paper_l)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else if(box_w + box_w + box_h + box_h > paper_w)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else 
					cout << "You do have enough wrapping paper, now you wrap them" << endl;
				}

return 0;
}



Am I missing somthing?? I can't see what is the problem???

Is This A Good Question/Topic? 0
  • +

Replies To: error C2447: '{' : missing function header (old-style formal l

#2 Cerolobo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 450
  • Joined: 05-April 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 05:55 PM

View PostKMH, on 5 May, 2008 - 05:42 PM, said:

This is FunctionCall

#include <iostream>
#include <cmath>
//Function proto type
#include "WrapFunction.h"

using namespace std;
{	
			   {
				if(box_l + box_l + box_h + box_h > paper_l)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else if(box_w + box_w + box_h + box_h > paper_w)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else 
					cout << "You do have enough wrapping paper, now you wrap them" << endl;
				}

return 0;
}



Am I missing somthing?? I can't see what is the problem???


You have the body of the function declared, but you do not tell the compiler what function the above code belongs to.

assuming the above code belongs to the function wrap

#include <iostream>
#include <cmath>
//Function proto type
#include "WrapFunction.h"

using namespace std;

bool wrap(float paper_w, float paper_l, float box_l, float box_w, float box_h) // Notice that there isn't a semicolon here
{	
			   {
				if(box_l + box_l + box_h + box_h > paper_l)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else if(box_w + box_w + box_h + box_h > paper_w)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else 
					cout << "You do have enough wrapping paper, now you wrap them" << endl;
				}

return 0;
}


Was This Post Helpful? 0
  • +
  • -

#3 KMH  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 80
  • Joined: 23-March 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 07:49 PM

Hello Cerolobo,

That was it the problem is fixed, I have declared the function just like you recommended but I didn't remove the semicolon at the end of the bool function.
Thanks for your help.
Was This Post Helpful? 0
  • +
  • -

#4 KMH  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 80
  • Joined: 23-March 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 07:55 PM

View PostCerolobo, on 5 May, 2008 - 05:55 PM, said:

View PostKMH, on 5 May, 2008 - 05:42 PM, said:

This is FunctionCall

#include <iostream>
#include <cmath>
//Function proto type
#include "WrapFunction.h"

using namespace std;
{	
			   {
				if(box_l + box_l + box_h + box_h > paper_l)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else if(box_w + box_w + box_h + box_h > paper_w)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else 
					cout << "You do have enough wrapping paper, now you wrap them" << endl;
				}

return 0;
}



Am I missing somthing?? I can't see what is the problem???


You have the body of the function declared, but you do not tell the compiler what function the above code belongs to.

assuming the above code belongs to the function wrap

#include <iostream>
#include <cmath>
//Function proto type
#include "WrapFunction.h"

using namespace std;

bool wrap(float paper_w, float paper_l, float box_l, float box_w, float box_h) // Notice that there isn't a semicolon here
{	
			   {
				if(box_l + box_l + box_h + box_h > paper_l)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else if(box_w + box_w + box_h + box_h > paper_w)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else 
					cout << "You do have enough wrapping paper, now you wrap them" << endl;
				}

return 0;
}


Was This Post Helpful? 0
  • +
  • -

#5 KMH  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 80
  • Joined: 23-March 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 08:27 PM

Hello Cerolobo,

In this case I no longer need to include the [#include"WrapFunction.h"] and what about
[return 0] and it shouldn't return [0] isn't it???
Was This Post Helpful? 0
  • +
  • -

#6 Cerolobo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 450
  • Joined: 05-April 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 08:43 PM

Here is the basic of a function declaration

<Return Type> <Function Name>(<Paramaters>)

and here is how you declared warp()

bool wrap(float paper_w, float paper_l, float box_l, float box_w, float box_h)

Since you declared the function to return a bool, you have to return something in warp. If you don't want to return anything from wrap, you change the return type to void.


No, you do not have to include
#include "WrapFunction.h"

in the file that contains the function. Function prototypes tell the compiler what to do when it finds a specific word. For example

#include <stdio.h>

  /* Tell the compile what foo and bar are */
void foo(void); /* semicolons tell the compiler that the code is declared somewhere else */
void bar(void);

int main(void)
{
  foo();
  bar();

  return 0;
}

  /* Now, define the actual function */
void foo(void)
{
  printf("This is function foo\n");
}

void bar(void)
{
  printf("This is function bar\n");
}



This can be written as
#include <stdio.h>

  /* No function prototype is needed, since the functions are defined here. */
void foo(void)
{
  printf("This is function foo\n");
}

void bar(void)
{
  printf("This is function bar\n");
}

int main(void)
{
  foo();
  bar();

  return 0;
}



If a function is defined before they are called in another function, then you don't have to add the prototype. Personally, I like to keep main() at the top of my code, so that you don't have to search for the entry point of the program.

Function prototypes are required if you separate code into different files. You can do hackish thing with #include, but that will more then likely cause issues.
Was This Post Helpful? 0
  • +
  • -

#7 KMH  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 80
  • Joined: 23-March 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 08:56 PM

I see, when I run the code after enter the values for the box and for wrapping paper, it did not do caculation and display the message, and when I [return wrap;] there are compiled error. [return wrap] should return the caculation values and dispaly the message right?
Was This Post Helpful? 0
  • +
  • -

#8 Cerolobo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 450
  • Joined: 05-April 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 09:08 PM

You don't want to do something like

bool wrap(float paper_w, float paper_l, float box_l, float box_w, float box_h) // Notice that there isn't a semicolon here
{	
			   {
				if(box_l + box_l + box_h + box_h > paper_l)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else if(box_w + box_w + box_h + box_h > paper_w)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else
					cout << "You do have enough wrapping paper, now you wrap them" << endl;
				}

return warp; // You are returning a function pointer, not a bool
}



Lets walk through the function warp.

When you call warp, you pass in the length, width, and height of the paper & box.

Inside of warp, you do the first check

if(box_l + box_l + box_h + box_h > paper_l)
  cout << "You do not have enough wrapping paper to wrap this box" << endl;


If box_l + box_l + box_h + box_h > paper_l is true, then "You do not have enough wrapping paper to wrap this box" will be printed to the command prompt. If it is false, then nothing will be printed to the command prompt, and then the 2nd if statement is checked. And so on.

Once that is done, you return from your function. If you keep the function as

bool wrap(float paper_w, float paper_l, float box_l, float box_w, float box_h)

you have to return a value. A bool can either be a 0 (false) or a 1(true).

If you change the return type, the return statement will be different.

I'm not sure what you want to return, but since you print out a message to the command prompt, it seems like you don't have to return anything.

To do this, you change the return type to void, which means don't return anything.

void wrap(float paper_w, float paper_l, float box_l, float box_w, float box_h)

Then, you can either remove the

return 0;

or just do

return;
Was This Post Helpful? 0
  • +
  • -

#9 KMH  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 80
  • Joined: 23-March 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 09:30 PM

Yes that is correct, since I do not return any values but just print the prompt message to let the user know if they have enought paper or not. I have used [void ] void wrap(float paper_w, float paper_l, float box_l, float box_w, float box_h)
[/void] still did not print the message nor it do the calculation, if I put this part of the code back in main it work nicely
 {
				if(box_l + box_l + box_h + box_h > paper_l)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else if(box_w + box_w + box_h + box_h > paper_w)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else 
					cout << "You do have enough wrapping paper, now you wrap them" << endl;
				}

.

This post has been edited by KMH: 05 May 2008 - 09:31 PM

Was This Post Helpful? 0
  • +
  • -

#10 Cerolobo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 450
  • Joined: 05-April 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 09:33 PM

Did you actually call the function in main()?
Was This Post Helpful? 0
  • +
  • -

#11 KMH  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 80
  • Joined: 23-March 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 10:03 PM

yes I called [#include"WrapFunction.h"] in main()

View PostCerolobo, on 5 May, 2008 - 09:33 PM, said:

Did you actually call the function in main()?

This post has been edited by KMH: 05 May 2008 - 10:07 PM

Was This Post Helpful? 0
  • +
  • -

#12 Cerolobo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 450
  • Joined: 05-April 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 10:13 PM

That's not how you call a function...

#include "WrapFunction.h"

Is used to include your prototype of the function, so you can call warp() from the file that contains main().

Again, looking at the general from of a function

<Return Type> <Function Name>(<Paramaters>)

For example (function prototype)

int add(int a, int b );

This functions takes two integers, and returns one integer.

Here is the actual code for it.

int add(int a, int b)
{
  return a + b;
}



Now, to use this, you simply type in the function name, with the parameters in brackets.

#include <stdio.h>

int add(int a, int b);

int main(void)
{
  int i = add(5, 3);

  printf("%d\n", i); /* this will print out 8, since 5 + 3 = 8 */

  return 0;
}

int add(int a, int b)
{
  return a + b;
}



edit: Damn emoticons...

This post has been edited by Cerolobo: 05 May 2008 - 10:14 PM

Was This Post Helpful? 0
  • +
  • -

#13 KMH  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 80
  • Joined: 23-March 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 10:48 PM

yeah I have try called function in [int main(void)] still didn't work, it seem like I can't move all the conditional operators from main.cpp to FunctionCall.cpp file by it self.

This post has been edited by KMH: 05 May 2008 - 10:56 PM

Was This Post Helpful? 0
  • +
  • -

#14 Cerolobo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 450
  • Joined: 05-April 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 05 May 2008 - 11:12 PM

No, you can separate it into a separate file. You can post your latest code, with the modifications, so I can get a better idea of what's happening?
Was This Post Helpful? 0
  • +
  • -

#15 KMH  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 80
  • Joined: 23-March 08

Re: error C2447: '{' : missing function header (old-style formal l

Posted 06 May 2008 - 10:16 AM

Hello Cerolobo,

Here is the latest mod code

This is header
//Function proto type
//bool wrap(float paper_w, float paper_l, float box_l, float box_w, float box_h);

void wrap(float paper_w, float paper_l, float box_l, float box_w, float box_h);



This is main.cpp
#include <iostream>
#include <cmath>
#include "WrapFunction.h"
using namespace std;

int main(void)
{
			float box_l = 0;
			float box_w = 0;
			float box_h = 0;
			float paper_w = 0;
			float paper_l = 0;
			cout << "Enter the box length in inches: ";
			cin >> box_l;
			cout << "Enter the box width in inches: ";
			cin >> box_w;
			cout << "Enter the box heigth in inches: ";
			cin >> box_h;
			cout << "Enter the wrapping paper width in inches: ";
			cin >> paper_w;
			cout << "Enter the wrapping paper length in inches: ";
			cin >> paper_l;
			cin.get();
				/*{
				if(box_l + box_l + box_h + box_h > paper_l)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else if(box_w + box_w + box_h + box_h > paper_w)
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else 
					cout << "You do have enough wrapping paper, now you can wrap them." << endl;
				}*/
			
cin.get();
return 0;

}



This is FunctionCall.cpp

#include <iostream>
#include <cmath>

using namespace std;

//Function proto type
//bool wrap(float paper_w, float paper_l, float box_l, float box_w, float box_h)
void wrap(float paper_w, float paper_l, float box_l, float box_w, float box_h)

{	
			
				if(box_l + box_l + box_h + box_h > paper_l)
					
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else if(box_w + box_w + box_h + box_h > paper_w)
					
					cout << "You do not have enough wrapping paper to wrap this box" << endl;
				else
					
					cout << "You do have enough wrapping paper, now you can wrap them" << endl;
			

return;

}


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2