Matjaz Depolli Guest
|
Posted: Thu Jun 08, 2006 2:03 am Post subject: template parameter's namespace exposed? |
|
|
I've got a problem that I will try to demonstrate with the following
code:
namespace N {
class A {
};
template<class T1, class T2>
T1 operator+ (T1 op1, T2 op2) {return op1;}
}
template<class T>
class B {
};
int main() {
N::A a1, a2;
a1 + a2; // works as it should
B<N::A> b1, b2;
b1 + b2; // oops, this one compiles too!
B<int> b3, b4;
b3 + b4; // no match for operator +, just the way it should be
}
The unwanted behaviour here is, that templated operator inside the
namespace makes itself visible to the templated classes outside that
namespace, instantiated with a member of the same namespace as their
template parameter. It is not like B extends N::A, in which case this
would be ok.
Just for the background of the problem - I've written expression
templates for my algebraic vector class and found myself bumping my
head into this wall. Now I can't even make my vector part of std
containers because operator+ messes too much with their inner workings.
I find this problem quite surprising and I'm wandering whether this is
a gcc bug (I'm using gcc version 3.4.4 -mingw special) or is this the
way the standard says it should be. If the latter is the case than I
have just found out the hard way that fully templated operators are too
great of a beast to let loose - even in a well hidden namespaces :)
Thanks in advance
Matjaz
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|