I have the following code compiled by gcc:
#include <iostream>
using namespace std;
class Buffer {
public:
operator char *() { cout << "operator const * called" << endl; return buff; }
private:
char buff[1024];
};
int main(int, char**) {
Buffer b;
(char *)b; // Buffer::operator char * is called here
return 0;
}
What I see is that Buffer::operator char * is called on line:
(char *)b;
Why C style cast calls Buffer::operator char * is called here?
I though that
static_cast<char *>(b);
should be used in order to invoke explicitly Buffer::operator char *.