#include #include namespace A { template class X { public: X() { } X(T t) : _t(t) { } const T &the_t() const { return _t; } private: T _t; }; template struct multiply_traits; template struct multiply_traits, T2> { typedef X result_type; }; template typename multiply_traits, T2>::result_type operator*(const X &x, const T2 &t) { return X(x.the_t() * t); } template T make(); template struct multiply_traits { BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested, make() * make()) typedef typename nested::type type; }; } namespace B { template class Y { public: Y(T t) : _t(t) { } const T &the_t() const { return _t; } private: T _t; }; template // Y::result_type> #if 0 I do not want to write in the above way. Because if I write in the above way, 'multiply_traits' has to be in namespace A. If the types T1 and T2 are not in namespace A, it would be awkward to defined 'multiply_traits' for them in namespace A. This is why I want the following way of deriving the template argument to Y, which does not need specify the namespace at all. The result type is derived from the function argument types directly. But it would end up with a compiler bug. My original question is still not addressed. Would you please take a further look on how to solve this problem? Or it can not be solved at this moment? #endif Y operator*(const Y &y, const T2 &t) { return Y(y.the_t() * t); } } int main () { A::X x(2); B::Y > y(x); std::cout << (x * 3).the_t() << std::endl; std::cout << (y * 5).the_t().the_t() << std::endl; }