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?
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
0
yes
0
yes
0
yes
0
Can you tell me the process for creating the header file?
0
yes we can make our own header file.
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.