problem about putting prototypes in header files.

closed account (LUXNwA7f)
Hey, guys.
I am learning separate files, and when I try to putting a function prototype into one user-defined header file, i met a error. Plz help me see where am I wrong, thx :)

display_prototype.h
1
2
3
4
#ifndef display_H
#define display_H
void display(int x);
#endif 


test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include "display_prototype.h"

using namespace std;

int main()
{
	display(5);
}

void display(int m)
{
	cout << "There are " << m << "apples in the box." << endl;
}


The wrong info is: expect an identifier.
closed account (LUXNwA7f)
And my implementation is VC++2010.
It compiles fine for me (Visual Studio 2012). Which line is giving you the error?
closed account (LUXNwA7f)
ya, now it works...
and another code, i can't run, others can, and he gave me the project running on his computer with my code, he succeed...
I don't why........... my implementation just fight again me :I

//cc.cpp
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;
void hello(int);
int main()
{
hello(5);
cin.get();
}


//cc2.cpp
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;
void hello(int);
void hello(int x)

{
cout << "OK" << endl;
}
closed account (LUXNwA7f)
i faint... i finally find that my second file haven't been auto add into the source file list.
Topic archived. No new replies allowed.