Type Cast Overloading

Heya there, I'm currently working on a header file which does some basic vector maths. I was wondering if it is possible to convert an instance of a custom class to one of the fundamental types, like double, in my case.
Basically, what I want to do is overload the type cast operator, so that it accepts my CVector and returns a double which represents the length of the vector.

Thanks in advance,


Kyon
Last edited on
I think you may be looking for this:

1
2
3
4
5
6
7
8
9
10
11
12
13
class CVector
{
public:

    // provide a type cast operator
    // from CVector to double
    operator double()
    {
        double d;
        // ... prepare d 
        return d;
    }
};
Last edited on
That did the trick, didn't know type cast overloading was part of the operator overloading. Thanks! :D
Topic archived. No new replies allowed.