By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 810 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Templatized operator () overload

P: n/a
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.

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Paul Escherton" <pe***@incongruous.net> wrote in message
news:3f*********************@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!

Jul 19 '05 #2

P: n/a
On Sun, 09 Nov 2003 22:24:17 -0700, Paul Escherton
<pe***@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
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.