Re: Template member function overload

Discussion in 'C++' started by Victor Bazarov, Jul 31, 2003.

  1. "Manuel González Castro" <> wrote...
    > Hello,
    >
    > I'd like to have 2 overloaded methods "parse" in my class,


    They are not overloaded. The one in the derived class _hides_
    the one in the base.

    > one of them
    > comming from a base class template speciallization and the other one added
    > in the derived Class:
    >
    > ------- file "MyTemplate.h" -------
    > #include <iostream>
    > template<class my_type> class MyTemplate {
    > public:
    > virtual void parse(double input) { } // This is the 1st method
    > // other member functions ...
    > };
    > ------- file "MyClass.h" -------
    > #include "MyTemplate.h"
    > #include <string>
    > class MyClass : public MyTemplate<std::string> {
    > public:
    > virtual void parse(char* input) { } // This is the 2nd method


    Add here:

    using MyTemplate<std::string>::parse;

    > };
    >
    > ------- file "main.cpp" -------
    > #include "MyClass.h"
    > int main()
    > {
    > double x = 0.0;
    > MyClass myclass;
    > myclass.parse(x); // line #6 gives a compile error !
    > return 0;
    > }
    > ------- end of code -------
    >
    > I get and error in line #6:
    > 'parse': cannot convert parameter 1 from 'double' to 'char *
    >
    > Why can't the compiler find the method void parse(double input) ?


    Because it's hidden.

    Victor
     
    Victor Bazarov, Jul 31, 2003
    #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. Piotre Ugrumov
    Replies:
    3
    Views:
    392
    Nick Hounsome
    Jan 25, 2004
  2. Replies:
    1
    Views:
    483
    Victor Bazarov
    Jul 20, 2005
  3. Peng Yu
    Replies:
    3
    Views:
    805
    Thomas J. Gritzan
    Oct 26, 2008
  4. Ying-Chieh Liao

    function overload (not operator overload)

    Ying-Chieh Liao, Oct 11, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    277
    Sherm Pendley
    Oct 11, 2004
  5. W Karas
    Replies:
    3
    Views:
    276
    Victor Bazarov
    Nov 30, 2012
Loading...

Share This Page