0

I have asked this question before on a different forum without success. I would like to know how to do templated type conversions for a class. The syntax is getting me though. Here is what I want:

class Thing
{
    public:
    template <typename T>
    T operator T();
}

This would allow me to cast my class to anything! Is this possible?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Labdabeta
1

The syntax is:

class Thing
{
    public:
    template <typename T>
    operator T(); //notice, no return type (it is implicit for conversion operators)
}

And it certainly is possible (at least it works on GCC). I'm not sure why you would want to do that, but you can.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.