| View previous topic :: View next topic |
| Author |
Message |
vpuvvada Guest
|
Posted: Fri Jul 29, 2005 1:51 pm Post subject: Function call resolution using argument namespace lookup doe |
|
|
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
|
Posted: Fri Jul 29, 2005 2:52 pm Post subject: Re: Function call resolution using argument namespace lookup |
|
|
"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
|
Posted: Mon Aug 01, 2005 2:19 pm Post subject: Re: Function call resolution using argument namespace lookup |
|
|
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 |
|
 |
|