| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Paul Escherton" |
| Date: |
09 Nov 2003 11:24:17 PM |
| Object: |
Templatized operator () overload |
I'm trying to templatize the operator(), but VisualStudio .NET 2003 I
get an odd error. I'm wondering if there is a way to do this and what
the proper syntax is. If there is not, why not?
My code looks like:
class DaClass
{
public:
template <class T> T operator( ) ( )
{
return T;
}
};
and I attempt to call the operator like this:
DaClass daClass;
daClass<bool>( );
daClass<bool>operator( );
I get an error on both the lines where I try to call the operator of:
'type 'bool' unexpected'.
Any thoughts? Thanks in advance.
.
|
|
| User: "Dave" |
|
| Title: Re: Templatized operator () overload |
09 Nov 2003 11:33:52 PM |
|
|
"Paul Escherton" <pesch@incongruous.net> wrote in message
news:3faf20f7$0$200$75868355@news.frii.net...
I'm trying to templatize the operator(), but VisualStudio .NET 2003 I
get an odd error. I'm wondering if there is a way to do this and what
the proper syntax is. If there is not, why not?
My code looks like:
class DaClass
{
public:
template <class T> T operator( ) ( )
{
return T;
}
};
and I attempt to call the operator like this:
DaClass daClass;
daClass<bool>( );
daClass<bool>operator( );
I get an error on both the lines where I try to call the operator of:
'type 'bool' unexpected'.
Any thoughts? Thanks in advance.
Your trying to return a type? ("return T;") Can't do dat! You need to
return a value of the type!
.
|
|
|
|
| User: "tom_usenet" |
|
| Title: Re: Templatized operator () overload |
10 Nov 2003 05:18:48 AM |
|
|
On Sun, 09 Nov 2003 22:24:17 -0700, Paul Escherton
<pesch@incongruous.net> wrote:
I'm trying to templatize the operator(), but VisualStudio .NET 2003 I
get an odd error. I'm wondering if there is a way to do this and what
the proper syntax is. If there is not, why not?
My code looks like:
class DaClass
{
public:
template <class T> T operator( ) ( )
{
return T;
}
};
and I attempt to call the operator like this:
DaClass daClass;
daClass<bool>( );
daClass<bool>operator( );
The above syntax is wrong. How about:
daClass.operator()<bool>();
But why do you want to template operator() it only on the return type?
I can't think of any use for that, since you can't call the function
without explicit template parameters.
Tom
.
|
|
|
|

|
Related Articles |
|
|