0
Can any one tell me how can we make header file in C++?
plz tell me some hint to do this
5 odpowiedzi
+ 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.
+ 1
thanx for giving link of site learn C++
+ 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]
0
Babak Sheykhan
sorry friend I can't understand it
completely.
I am begginer in C++
but thanx for your good support.