V
Victor Bazarov
Hi All
Given the following:
// NamespaceTemplate.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
namespace N1
{
class C1
{
public:
void f() {}
void g() {}
};
class C2
{
public:
typedef C1 buddy;
void h(C1 info) {}
void i() {}
};
}
namespace N2
{
class C1
{
public:
void f() {}
void g() {}
};
class C2
{
public:
typedef C1 buddy;
void h(C1 info) {}
void i() {}
};
}
template <typename T>
void k(T x)
{
C1 theProblem; // Ambiguous!! How to create the correct object???
typename T::buddy theProblem;
x.h(theProblem);
x.i();
}
using namespace N1;
using namespace N2;
Do you really need those 'using' directives here?
int main(int argc, char* argv[])
{
N1::C2 b;
k(b); // Invoke Template function
N2::C2 d;
k(d); // Invoke Template function
return 0;
}
What is the best way (that is, the most common way) to resolve the
issue above? I get an ambiguous symbol error when compiling, which
does make sense. I'm looking for a way to resolve this without
resorting to passing in enumerated types representing objects or
something like that.
V