PHP Code:
#include <iostream>
#include <string>
#include "class_interface.h"
using namespace std;
int main (){
interface obj(1,2); // create an interface object;
obj.print(); // print memebers data;
return 0;
}
PHP Code:
#ifndef Test_class_interface_h
#define Test_class_interface_h
class implementation;
class interface {
public:
interface (int a = 0, int b = 0);
void print();
private:
implementation * ptr;
};
#endif
PHP Code:
#include "class_interface.h"
#include <iostream>
using namespace std;
////////////////////////////// implementation
class implementation {
public:
implementation(int a = 0, int b = 0)
: var1(a), var2(b)
{}
void print(){
cout << var1 << endl;
cout << var2 << endl;
}
private:
const int var1;
const int var2;
};
/////////////////////////////// interface
interface::interface(int a, int b)
: ptr(new implementation(a,b)){}
void interface::print(){
ptr->print();
}