I’m self learning C++ from a book (Schaums Programming with c++) and i’ve come across something i want to try but it doesn’t cover(as fair as i can tell).
I have a class that contains hrs:mins:secs.
Is it possible to write a type conversion that will return the Object in form of a total as an integer?
If not that may be why i can not find anything. Thanks.
Sure, you just have to write a cast operator. Assuming you want to convert your time to seconds:
In C++11 you can also add the keyword
explicitto your operator so that your cast will explicitly require astatic_cast<int>in order to compile.