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 

Function call resolution using argument namespace lookup doe

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





PostPosted: Fri Jul 29, 2005 1:51 pm    Post subject: Function call resolution using argument namespace lookup doe Reply with quote



Given below the C++ code.

namespace Avg_User{
class Date{
};

template <typename T>
void f(T d)
{
}
typedef int Int_type;
typedef Date Date_type;
}

void foo(Avg_User::Date_type d,Avg_User::Int_type i)
{
f(d); // Looks at agument 'd's namespace and
//resolves using Avg_User::f(Avg_User::Date_type)
f(i); // ERROR: can not resolve using
// Avg_User::f(Avg_User::Int_type) using argument 'i's
namespace
}

Why C++ can not resolve function call by looking at its argument's
namespace
when its argument type is primitive which is a typedef in its own
namespace
using namespace resolution rules when function can not be found in the
present
scope ?


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Gianluca Silvestri
Guest





PostPosted: Fri Jul 29, 2005 2:52 pm    Post subject: Re: Function call resolution using argument namespace lookup Reply with quote




"vpuvvada" <venkat.puvvada (AT) gmail (DOT) com> ha scritto nel messaggio
news:1122639908.660237.9660 (AT) o13g2000cwo (DOT) googlegroups.com...
Quote:
Given below the C++ code.

namespace Avg_User{
class Date{
};

template void f(T d)
{
}
typedef int Int_type;
typedef Date Date_type;
}

void foo(Avg_User::Date_type d,Avg_User::Int_type i)
{
f(d); // Looks at agument 'd's namespace and
//resolves using Avg_User::f(Avg_User::Date_type)
f(i); // ERROR: can not resolve using
// Avg_User::f(Avg_User::Int_type) using argument 'i's
namespace
}

Why C++ can not resolve function call by looking at its argument's
namespace
when its argument type is primitive which is a typedef in its own
namespace
using namespace resolution rules when function can not be found in the
present
scope ?

typedef is only an alias, it doesn't mind where it is declared. So
Avg_User::Int_type is *really* an int and ADL has no place in the function
call.

HTH
Gianluca


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
vsnadagouda@gmail.com
Guest





PostPosted: Mon Aug 01, 2005 2:19 pm    Post subject: Re: Function call resolution using argument namespace lookup Reply with quote



Hello vpuvvada,

I tried your piece of code on Linux 8 box with GCC 3.0.3. It got
compiled without any errors or warnings.

Cheers
-Vallabha
vpuvvada wrote:
Quote:
Given below the C++ code.

namespace Avg_User{
class Date{
};

template void f(T d)
{
}
typedef int Int_type;
typedef Date Date_type;
}

void foo(Avg_User::Date_type d,Avg_User::Int_type i)
{
f(d); // Looks at agument 'd's namespace and
//resolves using Avg_User::f(Avg_User::Date_type)
f(i); // ERROR: can not resolve using
// Avg_User::f(Avg_User::Int_type) using argument 'i's
namespace
}

Why C++ can not resolve function call by looking at its argument's
namespace
when its argument type is primitive which is a typedef in its own
namespace
using namespace resolution rules when function can not be found in the
present
scope ?

[ 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.