R
Rafal 'Raf256' Maj
Hi,
I have base class that defines function 'fun'. This function is overloaded
- it can be used fr argument int or for const char* Function is virtual.
Now I create a dervied class cB, and I create new definitions of both
cB::fun - cB::fun(int) and cB::fun(const char*) - all is o.k.
but - now I decided that function cB::fun(const char*) is same as from
cA, so I change it's body to :
cB::fun(const char* s) { cA::fun(s); }
(all is stil ok) - and finaly I commented out the cB::fun(const char* s)
function, so that inherit mechanizm can take care of it. But then -
compiler acts like thar is no cB::fun(const char* s);
problem when using this classes :
class cA {
public:
cA(){};
virtual void fun(int v) { ... }
virtual void fun(const char* v) { ... }
};
class cB : public cA {
public:
cB(){};
virtual void fun(int v) { gConsole->Print("cB-int\n"); }
// !!! virtual void fun(const char* v) { ... }
void xxx() { ... }
};
cB *p = new cB;
p->xxx(); // ok
p->fun(3); // ok
cA->fun("a"); // compiler error - it doesn't see cB::fun(const char*)
// ant therefore it tries to convert const char* into 'int' and call
// cB::fun(int), instead of calling inherited cA::fun(const char*)
((cA*)p)->fun("a"); // this do work "manualy"
cB b;
b.fun("a"); // same compiler error
currently I use a workaround
void cB::fun(const char* v) { cA::fun(v); }
so i'm manualy calling cA's version of fun() instead of just inheriting it
but it's only a (bad) workaround
I have base class that defines function 'fun'. This function is overloaded
- it can be used fr argument int or for const char* Function is virtual.
Now I create a dervied class cB, and I create new definitions of both
cB::fun - cB::fun(int) and cB::fun(const char*) - all is o.k.
but - now I decided that function cB::fun(const char*) is same as from
cA, so I change it's body to :
cB::fun(const char* s) { cA::fun(s); }
(all is stil ok) - and finaly I commented out the cB::fun(const char* s)
function, so that inherit mechanizm can take care of it. But then -
compiler acts like thar is no cB::fun(const char* s);
problem when using this classes :
class cA {
public:
cA(){};
virtual void fun(int v) { ... }
virtual void fun(const char* v) { ... }
};
class cB : public cA {
public:
cB(){};
virtual void fun(int v) { gConsole->Print("cB-int\n"); }
// !!! virtual void fun(const char* v) { ... }
void xxx() { ... }
};
cB *p = new cB;
p->xxx(); // ok
p->fun(3); // ok
cA->fun("a"); // compiler error - it doesn't see cB::fun(const char*)
// ant therefore it tries to convert const char* into 'int' and call
// cB::fun(int), instead of calling inherited cA::fun(const char*)
((cA*)p)->fun("a"); // this do work "manualy"
cB b;
b.fun("a"); // same compiler error
currently I use a workaround
void cB::fun(const char* v) { cA::fun(v); }
so i'm manualy calling cA's version of fun() instead of just inheriting it
but it's only a (bad) workaround