Why is the fun function not suitable for ADL?

I have a simple namespace

one that has one variable and one function. In main

I am trying to call a function without a namespace qualifier and a variable with a namespace qualifier.

namespace SAM
{
    int p = 10;
    void fun(int)
    {
        cout<<"Fun gets called";
    }
} 

int main()
{

    fun(SAM::p);//why SAM::fun is not get called?
    return 0;
}

      

I can't name the fun, why isn't it suitable for ADL (Argument-dependent name lookup)?

I am getting the following error in Visual Studio.

'fun': id not found

If i use SAM::fun

it works.

+3


source to share


1 answer


ADL is taken for a type, not a variable, for example

namespace SAM
{
    struct P {};
    void fun(P)
    {
        cout<<"Fun gets called";
    }
} 

int main()
{
    SAM::P p;
    fun(p);
    return 0;
}

      



In the C ++ programming language, argument-dependent lookup (ADL) or argument-dependent name lookup applies an unqualified function name lookup based on the types of arguments given to the function call.

Ref: Finding Argument-Dependent Names

+5


source







All Articles