Re: Template member function overload



 DEVELOP > c-Plus-Plus > Re: Template member function overload

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1
Topic: DEVELOP > c-Plus-Plus
User: "Victor Bazarov"
Date: 31 Jul 2003 11:15:48 AM
Object: 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
.

 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER