Top "Conversion-operator" questions

A language feature to allow an object to specify how it can be converted to another type, either implicitly to satisfy a type restriction or explicitly.

What is the meaning of "operator bool() const"

For example: operator bool() const { return col != 0; } col is an int. How does operator bool() const work?

c++ operators implicit-conversion conversion-operator
Conversion Operators in C++

Please help me understand how exactly the conversion operators in C++ work. I have a simple example here which I …

c++ conversion-operator
What is an "operator int" function?

What is the "operator int" function below? What does it do? class INT { int a; public: INT(int ix = 0) { a = …

c++ terminology conversion-operator
How do conversion operators work in C++?

Consider this simple example: template <class Type> class smartref { public: smartref() : data(new Type) { } operator Type&(){ return *…

c++ conversion-operator
Conversion constructor vs. conversion operator: precedence

Reading some questions here on SO about conversion operators and constructors got me thinking about the interaction between them, namely …

c++ constructor operators type-conversion conversion-operator
Const operator overloading problems in C++

I'm having trouble with overloading operator() with a const version: #include <iostream> #include <vector> using namespace …

c++ operators constants conversion-operator
C++ Conversion operator for converting to function pointer

I'm been grinding my head against an idea that is simple enough in my head, but I can't figure out …

c++ function-pointers conversion-operator
conversion operator as standalone function

Why does C++ require that user-defined conversion operator can only be non-static member? Why is it not allowed to use …

c++ type-conversion conversion-operator
Type Conversion/Casting Confusion in C++

What is Type Conversion and what is Type Casting? When should I use each of them? Detail: Sorry if this …

c++ type-conversion casting conversion-operator
operator T&() or operator T()?

In defining a conversion operator, is there any advantage of defining operator T() const; over operator T&(); operator const …

c++ reference conversion-operator