2

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?

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
user3922375
  • 49
  • 1
  • 2

1 Answers1

6

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 {
    // ...
}
Rakete1111
  • 47,013
  • 16
  • 123
  • 162