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 and type-dependent name resolution

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Michael Norrish
Guest





PostPosted: Tue May 22, 2007 5:26 am    Post subject: template and type-dependent name resolution Reply with quote



I'm confused by g++ 4.0.3's behaviour on the following program (and
its variants, indicated by comments):

----------------------------------------------------------------------
#include <iostream>
using namespace std;

namespace m0 {
namespace m {
class C { public: int x; };
}
}

namespace p {
template <class T> class Foo {
public:
T x;
int g() { return f(x); }
};
}

int h()
{
p::Foo<m0::m::C> foo;
return foo.g();
}

int main()
{
cout << h() << endl;
return 0;
}

namespace m0 {
// this works
namespace m {
int f (C &c) { cout << "Yay\n"; return 1; }
}
// but this does not
// int f(m::C &c) { cout << "Urk\n"; return 2; }
}

// this would also work (if m0::m::f isn't also around - if both are
// present, there is an ambiguous overloading error)
// int f(m0::m::C &c) { cout << "Cool\n"; return 3; }
----------------------------------------------------------------------

The first f (in m0::m) is found because it's in the same namespace as
the declaration of C.

The last f (commented out), is found by name resolution of the
template body, because it appears "in the namespace" of the template
definition. (Indeed, you can mask it by putting a declaration of f
into namespace p.) Of course, the last f is actually in the global
namespace, not in p, but p 'inherits' it.

The second f (commented out) is not found however, and this confuses
me. Why is the rule different for the namespaces associated with the
class argument as opposed to the template definition? I don't get any
inspiration from reading the language of 3.4.2 para 2, and 14.6.4.2)

Or is g++ just incorrect?

Thanks,
Michael.


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards 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.