This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] handling of 'operator' in cp_find_first_component



On Wednesday, April 23, 2003, at 07:27 PM, David Carlton wrote:


On Tue, 22 Apr 2003 10:33:05 -0400, Daniel Berlin <dberlin at dberlin dot org> said:

To answer whether you need the return type, let's add two
specializations here and make it worse:

template <> long foo (int a)
{
	return 9;
}
template <> int foo (int a)
{
	return 10;
}

Yeah, but that's illegal, isn't it? You can't have two functions that differ only in return type: otherwise, how would the compiler know which one to use in a call to foo?

I tried it out in GCC; the above doesn't compile (I guess templates
with 0 parameters aren't legal),

It's not a template, it's a specialization, i just didn't paste the right thing.
template <> int foo<int> (int a)
{
return 5;
}
template <> long foo<long> (int a)
{
return 9;
}
is what that should be.


You can have two templates that only differ in return type, and they become, when instantiated, two functions that only differ in return type.
--Dan



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]