I have problem defining operator bool() function outside the class
class A{
public:
explicit operator bool() const;
};
I am defining the function outside class as...
explicit A::operator bool() const {
...
}
I get this error - error: ‘explicit’ outside class declaration
What is it that am doing wrong?
Just like you're not supposed to write inline for the definition if you already wrote it for the declaration, you are not allowed to write explicit outside of a class definition:
It may only appear within the decl-specifier-seq of the declaration of such a function within its class definition.
So, just remove it:
/*explicit*/ A::operator bool() const {
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With