0

Can any one tell me how can we make header file in C++?

plz tell me some hint to do this

13th Apr 2018, 4:41 AM
amir sohel
5 odpowiedzi
13th Apr 2018, 5:23 AM
Uttam
Uttam - avatar
+ 2
No big deal, It was the simplest possible example out there. BTW, rather than getting frustrated, you are welcomed to asking question about it.
13th Apr 2018, 10:03 AM
Babak
Babak - avatar
+ 1
thanx for giving link of site learn C++
13th Apr 2018, 5:27 AM
amir sohel
+ 1
Outside the SL world, you'd usually write your header + its implementation in separate files. Why? For a variety of reasons. For example, you may code a custom PRNG for your entire projects and you will correctly decide to write a library for it. Then you include it in every project in which you need a random number generator. (code reusing methodology) Example: // Here is your header prototypes inside amir.h file. sometimes called interface. #include <string> #ifndef _AMIR_H #define _AMIR_H class Amir { public: Amir(); void talking(); void walking(); private: std::string language; int paceSpeed; }; #endif // Here is your header implementation inside amir.cpp file. #include <iostream> #include "amir.h" Amir::Amir() { language = "Parsi"; paceSpeed = 5; // 5km/h } void Amir::talking() { std::cout << "Amir is talking " << language << ".\n"; } void Amir::walking() { std::cout << "Amir is walking " << paceSpeed << " km/h\n"; } // Inside main.cpp where you use amir.h #include "amir.h" int main() { Amir amir_1; amir_1.talking(); amir_1.walking(); } Inside the SL world, that's the different story. Everything lies inside one single file. See my last published code to see the example. [https://code.sololearn.com/clP5vGcxl7MG]
13th Apr 2018, 7:29 AM
Babak
Babak - avatar
0
Babak Sheykhan sorry friend I can't understand it completely. I am begginer in C++ but thanx for your good support.
13th Apr 2018, 9:07 AM
amir sohel