Koenig lookup problem???

D

Dave

#include <iostream>

using std::cout;
using std::endl;

// #define CAUSE_ERROR

namespace N
{
struct foo_t {};
void foo_func(foo_t) {cout << "Got here!" << endl;}
}

int main()
{
#ifdef CAUSE_ERROR
// EXPECTED ERROR - the parentheses surrounding the function name inhibit
// argument-dependent (Koenig) lookup, so the identifier foo_func will
not
// be found.
(foo_func)(N::foo_t());
#else
foo_func(N::foo_t()); // This call should and does compile fine.

// Here, the same call that generates an error above works fine. I would
// have expected an error here due to the suppression of Koenig lookup
(as
// above). Is this behavior Standard-compliant, or have I indeed found a
bug
// in my implementation (VC++ 7.1)???
(foo_func)(N::foo_t());
#endif
}
 
T

tom_usenet

#include <iostream>

using std::cout;
using std::endl;

// #define CAUSE_ERROR

namespace N
{
struct foo_t {};
void foo_func(foo_t) {cout << "Got here!" << endl;}
}

int main()
{
#ifdef CAUSE_ERROR
// EXPECTED ERROR - the parentheses surrounding the function name inhibit
// argument-dependent (Koenig) lookup, so the identifier foo_func will
not
// be found.
(foo_func)(N::foo_t());
#else
foo_func(N::foo_t()); // This call should and does compile fine.

// Here, the same call that generates an error above works fine. I would
// have expected an error here due to the suppression of Koenig lookup
(as
// above). Is this behavior Standard-compliant, or have I indeed found a
bug
// in my implementation (VC++ 7.1)???
(foo_func)(N::foo_t());

Looks like a bug - your analysis is correct. VC seems to be thinking
that the use of N::foo_func adds an implicit using N::foo_func;
declaration.

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,148
Latest member
ElizbethDa
Top