| | |
Implicit declaration of function with header file
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
Dear c++ gurus,
I'm new in creating a header file. never try before.
ERm... i have write a header file with a program:
But it comes out saying that:
Implicit declaration of function 'short int DetectSensor(...)'
What happen? is it relate to my header file format is wrong?
Thanks.
Best regards,
Suraine
I'm new in creating a header file. never try before.
ERm... i have write a header file with a program:
C++ Syntax (Toggle Plain Text)
Header file: MySensor.H extern short int DetectSensor(int sensorvalue[10]) { ....; }
C++ Syntax (Toggle Plain Text)
Program file: MyFile.C #include <MySensor.H> short int i; int p, sensorvalue[10]; int getsensorvalue() { ...; } int main() { for( p = 0; p < 10; p++) { sensorvalue[p] = getsensorvalue();; } i = DetectSensor(sensorvalue); return 0; }
But it comes out saying that:
Implicit declaration of function 'short int DetectSensor(...)'
What happen? is it relate to my header file format is wrong?
Thanks.
Best regards,
Suraine
1. The header file should not have any code -- just function prototype
2. In the *.cpp file, enclose the name of your header file in quotes
extern short int DetectSensor(int sensorvalue[10]); Notice the semicolon at the end and there are no ( and )2. In the *.cpp file, enclose the name of your header file in quotes
#include "MySensor.H"; Angle bracks are for header files that are were supplied by your compiler, such as <string>. The ones you create are in your project's folder and should be surrounded by quotes. Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
Thanks, Ancient Dragon.
So, that means in header file. We can just declare the function prototype, but cant have its function definition.
only:
but not
function definition should be done in *.cpp file, right?
If it is, what is header file for? not for shorten the file length, but for?
Thanks again.
So, that means in header file. We can just declare the function prototype, but cant have its function definition.
only:
C++ Syntax (Toggle Plain Text)
extern short int DetectSensor(int sensorvalue[10]);
but not
C++ Syntax (Toggle Plain Text)
extern short int DetectSensor(int sensorvalue[10]); short int DetectSensor(int sensorvalue[10]) { function definition block; }
function definition should be done in *.cpp file, right?
If it is, what is header file for? not for shorten the file length, but for?
Thanks again.
Header files for mostly useful in multi-file projects where there are two or more *.cpp files which need to know about the same functions and definitions. Look in your compiler's include directory, it contains many header files. The ones you write are no different than those.
The more you write programs and header files the more useful they will appear to you. Especially when you begin to write multi-file programs. Many large projects consist of hundreds of *.cpp files, so common header files are absolutely essential.
The more you write programs and header files the more useful they will appear to you. Especially when you begin to write multi-file programs. Many large projects consist of hundreds of *.cpp files, so common header files are absolutely essential.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Errors in kernel header files while compiling a third party A/D card driver C code. (Kernels and Modules)
- Unknown prototype ... (C)
- My Lib management prog*****HELP ME**** (C++)
Other Threads in the C++ Forum
- Previous Thread: How can i do this ?
- Next Thread: Squares program: sentinel value and size of 0
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






