Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Template member function overload

Reply
Thread Tools

Re: Template member function overload

 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-31-2003
"Manuel González Castro" <(E-Mail Removed)> 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>:arse;

> };
>
> ------- 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Member vs. non-member operator overload disambiguation W Karas C++ 3 11-30-2012 06:34 PM
How to use the template member function of a template in the memberfunction of another template class? Peng Yu C++ 3 10-26-2008 03:51 PM
specialized member function takes precedence over generic template member function bluekite2000@gmail.com C++ 1 07-20-2005 08:58 PM
parse error in gcc but success in vc.net, call a non_template class's template member function from a template class's member function! ken C++ 2 06-28-2005 06:57 AM
function overload (not operator overload) Ying-Chieh Liao Perl Misc 3 10-11-2004 11:24 AM



Advertisments