0

Could someone please explain why the following code is giving error (error C2065: 'select' : undeclared identifier) at compile time:

namespace N { 
    class MyClass{ 

    }; 
    template<int I> void select(MyClass*)
    {}
}
void g (N::MyClass* mp) 
{ 
    select<10>(mp); 
}
void main()
{}

According to Argument Dependent Lookup, this should work fine, since I have specified N:: in `g``s argument. So, select should be visible to compiler.

Why does ADL not work here?

Sebastian Mach
  • 38,570
  • 8
  • 95
  • 130
Anitesh
  • 27
  • 6
  • 1
    This question already answered [here](http://stackoverflow.com/questions/2953684/why-doesnt-adl-find-function-templates) – Vasily Biryukov Oct 25 '13 at 11:07
  • btw, it's `int main()` or `int main(int argc, char* argv[])`, even if you do not `return` anything (in which case it is the same as returning `0`) – Sebastian Mach Oct 25 '13 at 11:34
  • "void main()" also works fine. I am working on VS 2008. May i know why have you explicitly mentioned it? It will be helpful for me if its important. Why main should return int? – Anitesh Oct 25 '13 at 12:02
  • @Anitesh: `main` should return `int` because that's the only portable return type specified by the language standard. Your compiler allows non-standard extensions, but most others don't. Posting non-standard code here makes the question harder to answer. – Mike Seymour Oct 25 '13 at 12:36

2 Answers2

0

have you tried N::select? either that or a

using namespace N

should work since simply select is not visible

Maggnetix
  • 114
  • 6
  • 1
    you cannot see it yet, but this is the fourth answer that states _use `N::select`_. But this is not an answer to the question. The question was about why ADL does not work here. – Sebastian Mach Oct 25 '13 at 11:36
  • I got my answer in this [link](http://stackoverflow.com/questions/2953684/why-doesnt-adl-find-function-templates). Please refer. – Anitesh Oct 25 '13 at 11:54
0

Any time you utilise a class from a divergent namespace from the one you are currently in you must either reference it directly (N::select) or set up a using namespace (using namespace N;) or set up a direct using statement to it for future use (using N::select)

For disambiguation I would look at this and this , which between them should give you a good start on how/why you cannot simply call select.

Cheers, and feel free to get a hold of me for more info.

Community
  • 1
  • 1
GMasucci
  • 2,834
  • 22
  • 42