How can I use the "X () operator" defined in the class?

I'm relatively new to C ++, and this expression confused me:

Service.h:

class ServiceHandle { public: ServiceHandle(SC_HANDLE h) : handle(h) {} ... operator SC_HANDLE() const {return handle;} protected: SC_HANDLE handle; }; 

I created the ServiceHandle object in other ways than the constructor specified here. I would like the actual SC_HANDLE switch to ChangeServiceConfig , how can I get this? I assume this is due to the operator, but I cannot figure out how to use it.

+4
source share
2 answers

You just use an object of type ServiceHandle in the expression tht expects SC_HANDLE . The statement you are talking about is a casting statement before SC_HANDLE . This operator is automatically used.

+4
source

This is a casting operator. This could be called:

 ServiceHandle s(some handle); SC_HANDLE h = (SC_HANDLE)s; 
0
source

Source: https://habr.com/ru/post/1379629/


All Articles