Overriding overloaded functions?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Generic Usenet Account

    Overriding overloaded functions?

    The code example below fails to compile under g++ and Solaris native
    CC and gives the following output:

    "main.cc", line 12: Warning: derived::func hides the virtual function
    base::func(int) .
    "main.cc", line 36: Error: Too few arguments in call to
    "derived::func( int, int)".
    1 Error(s) and 1 Warning(s) detected.

    Why would overriding the function 'int func(int a, int b)' in the
    derived class make the overriden function 'int func(int a)' in the
    base class not visible?

    Thanks in advance for your help.

    Tom Helfand

    ----- Begin main.cc -----

    #include <iostream.h>

    class base {
    public:
    virtual void func(int a);
    virtual int func(int a, int b);
    };

    class derived : public base {
    public:
    int func(int a, int b);
    };

    void
    base::func(int a) {
    cout << "base::func (int a)" << endl;
    }

    int
    base::func(int a, int b) {
    cout << "base::func (int a, int b)\n" << endl;
    return 0;
    }

    int
    derived::func(i nt a, int b) {
    cout << "derived::func( int a, int b)\n" << endl;
    return 0;
    }


    int
    main(int argc, char * argv[]) {
    derived *instance = new derived();

    instance->func(1);
    instance->func(1,2);
    }
  • Russell Hanneken

    #2
    Re: Overriding overloaded functions?

    Generic Usenet Account wrote:[color=blue]
    >
    > Why would overriding the function 'int func(int a, int b)' in the
    > derived class make the overriden function 'int func(int a)' in the
    > base class not visible?[/color]

    Here's a plausible explanation for the rule:



    See also



    and



    Regards,

    Russell Hanneken
    rhanneken@pobox .com

    Comment

    • Anchor

      #3
      Re: Overriding overloaded functions?


      I try it in VC6.0,but it is not helpful.??????? ???

      [color=blue]
      > Generic Usenet Account wrote:[color=green]
      > >
      > > Why would overriding the function 'int func(int a, int b)' in the
      > > derived class make the overriden function 'int func(int a)' in the
      > > base class not visible?[/color]
      >[/color]



      Comment

      Working...