Templatized operator () overload

P

Paul Escherton

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

Dave

Paul Escherton said:
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!
 
T

tom_usenet

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top