J
jayesah
I have following code:
#include <iostream>
using namespace std;
template <class T> class Parent
{
public:
void fun(const T a){ }
};
class myclass: public Parent<int*>
{
public:
void myclassfun(const int* a)
{
Parent<int*>::fun(a);
}
};
int main() {
myclass obj1;
int * ptr;
obj1.myclassfun(ptr);
return 0;
}
This gives me compilation error:
"In member function `void myclass::myclassfun(const int*)':
error: invalid conversion from `const int*' to `int*'
error: initializing argument 1 of `void Parent<T>::fun(T) [with T =
int*]' "
Please tell me what is the problem here ?
I am not allowed to change Parent class interface.
Jayesh
#include <iostream>
using namespace std;
template <class T> class Parent
{
public:
void fun(const T a){ }
};
class myclass: public Parent<int*>
{
public:
void myclassfun(const int* a)
{
Parent<int*>::fun(a);
}
};
int main() {
myclass obj1;
int * ptr;
obj1.myclassfun(ptr);
return 0;
}
This gives me compilation error:
"In member function `void myclass::myclassfun(const int*)':
error: invalid conversion from `const int*' to `int*'
error: initializing argument 1 of `void Parent<T>::fun(T) [with T =
int*]' "
Please tell me what is the problem here ?
I am not allowed to change Parent class interface.
Jayesh