0

We have two following codes:

First:

class base
{
public:
    static void nothing()
    {
        std::cout << "Nothing!" << std::endl;
    }
};

class derived : public base
{
    public:
    static void nothing(int a)
    {
        std::cout << "Nothing with " << a << std::endl;
    }

    static void nothing(double b)
    {
        std::cout << "Nothing with " << b << std::endl;
    }

    //using base::nothing;
};

int main()
{
    derived::nothing();

    return 0;
}

and the second one:

class base
{
    public:
    static void nothing()
    {
        std::cout << "Nothing!" << std::endl;
    }
};

class derived : public base
{
    public:
    /*static void nothing(int a)
    {
        std::cout << "Nothing with " << a << std::endl;
    }

    static void nothing(double b)
    {
        std::cout << "Nothing with " << b << std::endl;
    }
    */

    //using base::nothing;
};

int main()
{
    derived::nothing();

    return 0;
}

Question, why we cannot compile the first code ? The compiler is not able to find the inherited static method from base class, but sees only the methods from the derived class!

To compile the first example, we need to introduce the base::nothing name by 'using' declaration.

Could someone tell me why ? Why the declaration of a static 'nothing' method in the derived class, stops the compiler from seeing the inherited static methods from the base class ?

user1770426
  • 173
  • 1
  • 2
  • 12
  • 2
    See http://stackoverflow.com/questions/411103/function-with-same-name-but-different-signature-in-derived-class – Sedenion Jun 25 '14 at 11:17
  • Hi guys, thx for explanation. Indeed I have duplicate the topic Somehow I thought it is related only with static members, what mislead me search. Anyway thx! – user1770426 Jun 25 '14 at 12:30

0 Answers0