Announcement

Collapse
No announcement yet.

Manipulate class private member with externals functions and operators overload

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

  • Manipulate class private member with externals functions and operators overload

    PHP Code:
    //
    //  main.cpp
    //  Test
    //
    //  Created by Giovanni Di Grezia on 22/07/13.
    //  Copyright (c) 2013 Giovanni Di Grezia. All rights reserved.
    //
    //
    //
    //


    // pass an external function to a class acting on a private member

    #include <iostream>
    #include <string>
    #include <exception>
    #include <cmath>
    #include <iomanip>

    using namespace std;


    /////////////// external function
    int magia_su_numero (int input){
        return 
    input *2;

    }


    ///////////////////// test class
    class test{
    public:
        
        
    test(int input 1)
        :
    numero(input)
        {}
        
        
        
    template <typename AA do_funct (A passed_function(A) ){
            return 
    passed_function(numero);
        }
        
        
        
    private:
        
    int numero;
        
    };

    /////////////// overloaded operator >>

    int operator>> (int funct_to_pass (int ), test target){
        return ( 
    target.do_funct(funct_to_pass)  );

    }


        
    int main () {
            
            
    test obj;
            
            
    cout << (magia_su_numero >> obj) << endl;
            
            return 
    ;
        } 
    | 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