Please explain the reason of the error
-
Please explain why the error
class base { public: void fun1() { } virtual void call() { } }; class derive:public base { public: void call() { fun1(); // ERROR- function does not take 0 arguments } void fun1(int i) { } }
Regards Anil
Because
fun1
inderive
hides the definition offun1
inbase
. Usebase::fun1()
, like this:class base
{
public:
void fun1()
{
}virtual void call()
{
}
};class derive:public base
{
public:
void call()
{
**base::**fun1(); // ERROR- function does not take 0 arguments
}void fun1(int i)
{}
};Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Because
fun1
inderive
hides the definition offun1
inbase
. Usebase::fun1()
, like this:class base
{
public:
void fun1()
{
}virtual void call()
{
}
};class derive:public base
{
public:
void call()
{
**base::**fun1(); // ERROR- function does not take 0 arguments
}void fun1(int i)
{}
};Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Why the base::fun1() is needed ? If the fun1(int i) is not there then there is no error. Once the overload function is declare its giving the error.
Regards Anil
_anil_ wrote:
Why the base::fun1() is needed ? If the fun1(int i) is not there then there is no error. Once the overload function is declare its giving the error.
Did you even read my answer? To repeat what I said - the error's because fun1 in derive hides the definition of fun1 in base. It (fun1 in derive) is not an overload, because it's defined in a different scope than fun1 in base.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Why the base::fun1() is needed ? If the fun1(int i) is not there then there is no error. Once the overload function is declare its giving the error.
Regards Anil
With your
fun1(int)
in derived class you're hiding the base classfun1
. See here [^]. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
_anil_ wrote:
Why the base::fun1() is needed ? If the fun1(int i) is not there then there is no error. Once the overload function is declare its giving the error.
Did you even read my answer? To repeat what I said - the error's because fun1 in derive hides the definition of fun1 in base. It (fun1 in derive) is not an overload, because it's defined in a different scope than fun1 in base.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p