473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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.

Jul 19 '05 #1
2 2470

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hall | last post by:
I have a problem with my design of a templatized class. I'm trying to figure out how to load and save the data inside it, but can't. My class looks like this ------------------------------------...
5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
4
by: Chiller | last post by:
Ok, thanks to some good assistance/advice from people in this group I've been able to further develop my Distance class. Since previous posts I've refined my code to accept the unit measurement...
7
by: Sean | last post by:
Can someone help me see why the following "operator=" overloading doesn't work under g++? and the error message is copied here. I see no reason the compiler complain this. Thanks, $ g++...
17
by: Chris | last post by:
To me, this seems rather redundant. The compiler requires that if you overload the == operator, you must also overload the != operator. All I do for the != operator is something like this: ...
9
by: Tony | last post by:
I have an operator== overload that compares two items and returns a new class as the result of the comparison (instead of the normal bool) I then get an ambiguous operater compile error when I...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
1
by: StephQ | last post by:
I can't get this code working: class Scheme_euler { private: .... public: ....
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.