From: Andre Poenitz on
Hi all.

I have a problem figuring out what the correct way for a compiler
to handle the code below would be. [Also for the cases where
NAMESPACES and/or CONVERSION were #define'd to 1.]

/////////////////////////////////////////////////////////////////////

#include <iostream>

#define NAMESPACES 0
#define CONVERSION 0

#if NAMESPACES
# define BEGIN_NS namespace N {
# define END_NS }
# define NS N
#else
# define BEGIN_NS
# define END_NS
# define NS
#endif


BEGIN_NS
struct A {};
END_NS

void f(NS::A) { std::cout << "A\n"; }
void f(int) { std::cout << "int\n"; }


BEGIN_NS
template <typename T> inline void g(T t) { f(t); }
END_NS

BEGIN_NS
struct B {
#if CONVERSION
operator A() const { return A(); }
#endif
};
END_NS


void f(NS::B) { std::cout << "B\n"; }
void f(double) { std::cout << "double\n"; }


int main()
{
NS::g(NS::A());
NS::g(NS::B());
NS::g(int());
NS::g(double());
}

///////////////////////////////////////////////////////////////////

I've 'practically' checked two sets of compilers, several versions
of gcc produce

0/0: A B int int
1/0: line 37: no matching function for call to �f(N::B&)�
0/1: A B int int
1/1: A A int int

the other set (Redmond based) produces

0/0: A B int double
1/0: A B int double
0/1: A B int double
1/1: A B int double

Comeau online tells me that it won't compile case 1/0, so I take it as
an indication that it falls in the first category too.

My "Standardese" is too bad to parse Chapter 3.4 in a way that I'd
feel comfortable enough to find the answer myself.

Andre'

PS: Assuming that the first set of compilers is right, is there a way
to modify the code so that it produces "A B int double" without
changing the order of declarations?

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]