C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

template parameter's namespace exposed?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Matjaz Depolli
Guest





PostPosted: Thu Jun 08, 2006 2:03 am    Post subject: template parameter's namespace exposed? Reply with quote



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! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.