Does the following construct qualify as overloading on return type ?

Discussion in 'C++' started by Nikhil.S.Ketkar@gmail.com, Aug 15, 2008.

  1. Guest

    Hi,


    Does the following construct qualify as overloading on return type ?
    If not, in what way ? I overloaded the type conversion operator and
    used pointers to member functions. Its pretty straightforward but I
    am sure I have missed as this is not supposed to be possible. Am I
    misunderstanding overloading ?


    Thanks,
    Nikhil

    // foo() overloads on both input parameters and return value
    //-------------------------------------------------------------
    // int int_output = foo(int &int_input);
    // double double_output = foo(int &int_input);
    // int int_output = foo(double &double_input);
    // double double_output = foo(double &double_input);
    //-------------------------------------------------------------

    #include <iostream>

    class foo
    {
    public:
    foo(int *given) {given_int = given; int_ = &foo::int_int; double_ =
    &foo::double_int;}
    foo(double *given) {given_double = given; int_ = &foo::int_double;
    double_ = &foo::double_double;}
    operator double () { (this->*double_)(); }
    operator int () { (this->*int_)(); }
    private:
    double double_double() { std::cout << "--> foo called with input
    double and output double\n";}
    double double_int() { std::cout << "-->foo called with output
    double and output int was called\n";}
    int int_int() { std::cout << "-->foo called with input int and
    output int was called\n";}
    int int_double() { std::cout << "-->foo called with input int and
    output double was called\n";}
    int *given_int;
    double *given_double;
    int (foo::*int_)();
    double (foo::*double_)();
    };



    int main(int argc, char *argv)
    {
    double double_input, double_output;
    int int_input, int_output;

    std::cout << "Trying foo with int input and int output\n";
    int_output = foo(&int_input);

    std::cout << "Trying foo with int input and double output\n";
    double_output = foo(&int_input);

    std::cout << "Trying foo with double input and int output\n";
    int_output = foo(&double_input);

    std::cout << "Trying foo with double input and double output\n";
    double_output = foo(&double_input);

    }

    // Output

    // Trying foo with int input and int output
    // -->foo called with input int and output int was called
    // Trying foo with int input and double output
    // -->foo called with output double and output int was called
    // Trying foo with double input and int output
    // -->foo called with input int and output double was called
    // Trying foo with double input and double output
    // --> foo called with input double and output double
     
    , Aug 15, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. karim
    Replies:
    5
    Views:
    2,984
    David Waz...
    Jul 11, 2003
  2. Johs
    Replies:
    3
    Views:
    352
    Ron AF Greve
    Apr 22, 2007
  3. Mukesh
    Replies:
    4
    Views:
    633
    Paul N
    Mar 26, 2010
  4. Evert Wiesenekker

    Qualify/Reference datagrid cells by name

    Evert Wiesenekker, Jun 1, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    125
    Eliyahu Goldin
    Jun 1, 2004
  5. Hank
    Replies:
    6
    Views:
    129
    Lasse Reichstein Nielsen
    Aug 11, 2004
Loading...

Share This Page