Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: Template member function overload (http://www.velocityreviews.com/forums/t276241-re-template-member-function-overload.html)

Victor Bazarov 07-31-2003 04:15 PM

Re: Template member function overload
 
"Manuel González Castro" <iinmgc00@ucv.udc.es> 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




All times are GMT. The time now is 01:22 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.