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?

4
  • 1
    This question already answered here Commented Oct 25, 2013 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) Commented Oct 25, 2013 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? Commented Oct 25, 2013 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. Commented Oct 25, 2013 at 12:36

2 Answers 2

0

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

using namespace N 

should work since simply select is not visible

Sign up to request clarification or add additional context in comments.

2 Comments

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.
I got my answer in this link. Please refer.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.