Announcement

Collapse
No announcement yet.

Hiding class private member to client using a proxy class

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hiding class private member to client using a proxy class

    main.cpp
    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;



    class_interface.h
    PHP Code:
     #ifndef Test_class_interface_h
    #define Test_class_interface_h


    class implementation;
    class interface {
        
    public:

        interface (
    int a 0int b 0);
        
    void print();

    private:
        
    implementation ptr;
        
        
    };



    #endif 
    class_interface.cpp
    PHP Code:
      #include "class_interface.h"
    #include <iostream>

    using namespace std;


    ////////////////////////////// implementation

    class implementation {
        
        public:
            
    implementation(int a 0int 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 aint b)
    ptr(new implementation(a,b)){}

    void interface::print(){
        
    ptr->print();


    | VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio
Working...
X

Google Profile


My name is Giovanni Di Grezia, but people call me xgiovio.

Here is my homepage:.

I'm a VFX Artist and Software Developer.

Giovanni Di Grezia