I am reading book How to program by Paul Deitel. As per him we can make a file which does not contain member function details.
"To hide the class’s member-function implementation details, the class-implementation programmer would provide the client-code programmer with the header Time.h (which specifies the class’s interface and data members) and the Time object code (i.e., the machine-code instructions that represent Time’s member functions). The client-code programmer is not given Time.cpp, so the client remains unaware of how Time’s member functions are implemented."
I have developed below simple code in dev to test this concept but I don't know after compiling which file is the equivalent to cpp file.
Area Class:
#include<iostream>
using namespace std;
class Area {
public:
int square(int);
private:
int x;
};
Source Code Area.cpp which contains member function functionality
#include<iostream>
#ifndef AREA_HH
#define AREA_HH
# include "Area.h"
int Area::square(int x)
{
return x*x;
}
#endif
Main:
#include<iostream>
#include "Area.h"
using namespace std;
int main ()
{
Area Obj1;
cout<<Obj1.square(4);
return 0;
}
The Files created by Dev are: Area.cpp, Area.o,Area.h,main.cpp,main.o,Makefile.win,layout and exe.
Aucun commentaire:
Enregistrer un commentaire