Templatized operator () overload



 DEVELOP > c-Plus-Plus > Templatized operator () overload

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER