template class, operator T

C

Christopher

I am trying to re-write some code from a book I am working on so that I
understand it's functionality.
I ran across this:

template <class T>
class Flag
{
public:
// snip
T value;
operator T() {return value;};
// snip
};

what does the operator T do? and is it not returning a value even a void?
,
Christopher
 
J

Jeff Schwab

Christopher said:
I am trying to re-write some code from a book I am working on so that I
understand it's functionality.
I ran across this:

template <class T>
class Flag
{
public:
// snip
T value;
operator T() {return value;};
// snip
};

what does the operator T do? and is it not returning a value even a void?

It's returning a T. That function will be called whenever an object of
type Flag<T> is converted to type T.
 
R

Ralf

template said:
class Flag
{
public:
// snip
T value;
operator T() {return value;};
// snip
};

what does the operator T do? and is it not returning a value even a void?

It is an operator for type conversion. An object of the type Flag<T> can be
converted to T.

Ralf

www.oo-fabrik.de
 

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

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,414
Latest member
djangoframe

Latest Threads

Top