Ad Code

Seperation of interface and implementation?

Separation of interface and implementation?
I want to discuss with implement ion point of view.which I'm understand is that our interface is on .h or .hpp file or implement ion on .c or .cpp file how we link both file and how they communicate which each other.I want to understand the logic that I include .h file in my .cpp file(#include dummy.h;) and use .h file for accessing such .cpp file from other program.


In the header files you have declarations so you can use function, classes, whatever which are not defined in your source file (they can be defined in another source file you will compile or in a library, for template stuff, you will have the definition in the header)

having the code in multiple source files can be useful for large projects, here is an example of using headers for having the code split in two source files:

MyHeader.h
#ifndef MYHEADER
#define MYHEADER

    void sayHello();//declaration

#endif

MyHeader.cpp

#include <iostream>
#include "MyHeader.h"

void sayHello()//Implementation
{
    std::cout << "Hello!";
}

Main.cpp
#include "MyHeader.h"

int main()
{
    sayHello();//Call
    return 0;
}
Reactions

Post a Comment

0 Comments