how is the separation of interface and implementation of objects achieved in c++...can you give a simple example....................;)
Printable View
how is the separation of interface and implementation of objects achieved in c++...can you give a simple example....................;)
Interface is the declaration of the class in *.hpp file(eg. myclass.hpp) (header files)
Implementation is the code for the class(eg. myclass.cpp)
People usually give out only the *.hpp and the *.obj files if they want to keep the source code to themselves.
You can make it into a library or dll if you like.
Heres a simple example:
PHP Code://myclass.h
#ifndef __MYCLASS_H__
#define __MYCLASS_H__
class MyClass
{
MyClass();
virtual ~MyClass();
int function(int a);
};
#endif
PHP Code://myclass.cpp
#include "myclass.h"
MyClass::MyClass()
{
}
MyClass::~MyClass()
{
}
int function(int a)
{
return(a);
}