0

Can we create our own header files?

Like iostream includes cout and cin function.Can we place our own header file and store our own functions in header files?

6th Jul 2016, 3:49 PM
Satan 666
Satan 666 - avatar
7 odpowiedzi
+ 1
sure, when you create a class, let's say myClass.cpp. we want to be able to use that class on our main.cpp file, however if we just start calling methods and trying to instantiate objects from myClass.cpp we'll get errors since main.cpp doesn't know what that file is. what we can then do is create our header file which sort of links cpp files together. in our header file we'll have something like: #ifndef MYCLASS_H #define MYCLASS_H //our class #endif MYCLASS_H and if we name this file something like myClass.h, we can use it in our main.cpp file by typing: #include "myClass.h" and now we have access to myClass.cpp
6th Jul 2016, 4:42 PM
destro
0
yes
6th Jul 2016, 4:17 PM
Rajkumar
Rajkumar - avatar
0
yes
6th Jul 2016, 4:18 PM
Rajkumar
Rajkumar - avatar
0
yes
6th Jul 2016, 4:25 PM
Nakul Kumar
Nakul Kumar - avatar
0
Can you tell me the process for creating the header file?
6th Jul 2016, 4:28 PM
Satan 666
Satan 666 - avatar
0
yes we can make our own header file.
6th Jul 2016, 4:37 PM
Ruchir Gupta
0
I tried something in my turbo c++. I created a program and instead of putting any header files or anything, i just put a function definition(function to add two nos.) and saved the file as myheader.h. Now i opened up a new file and used this myheader.h and called the function add(which I had already defined in myheader.h file) and it worked perfectly fine.
6th Jul 2016, 7:11 PM
Satan 666
Satan 666 - avatar