What will be called when calling the callFunc method of the obj object:
template <class X> void func(X val) { }
template <> void func<double>(double val) { }

class A
{
    public:
        void callFunc() { func(4.5); }
    private:
        void func(int val) { }
};
Explanation
The compiler finds an element named func in the A class namespace, so it stops the search. An element named func in the A class does not have to be a function - it can be a regular class member. There can be many such elements - for example, an overloaded function. Next, the compiler searches for the most appropriate function among the found elements with the same name, which can be called with these arguments without converting the types of arguments or with an implicit conversion of the type of arguments of the function. In this case, it is void A::func(int); See also C++ lookup rules.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты