- Where Developers Learn, Share, & Build Careers
When trying to learn about Poco networking libraries, I came to the following snippet:
Class MyRequestHandlerFactory: Public HTTPRequestHandlerFactory { Public: Virtual HTTPRequestHandler * createRequestHandler (Const HTTserverRequest & amp;) {New MyRequestHandler Return; }};
I have a problem with the return type ( HTTPRequestHandler * ) and the method is unable to understand logic ( const HTTPServerRequest & amp; ). Why is it that the return type HTTPRequestHandler indicator? Does new MyRequestHandler return an address for an object which can be referenced in its base type? In addition, I understand that the const is used to make the context irreversible so that the method can not change the referenced object, but no name for the reference type Has been given and it is not being used in the createRequestHandler Can anyone tell me what's going on here? Thanks
return type If you see the "Learning Poko" code web site,
class MyRequestHandler: public HTTPRequestHandler {// ... deleted code}; MyRequestHandler is derived from HTTPRequestHandler Therefore, the MyRequanceHandler is an HTTPRequestHandler due to a legacy, so it is valid to return an indicator on a MyRequestHandler, because it is an HTTPRequestHandler indicator.
Function logic The snippet is confusing because it specifies no argument as a type but there is no variable name, it is exactly the same :
Class MyRequestHandlerFactory: Public HTTPRequestHandlerFactory {Public: Virtual HTTPRequestHandler * createRequestHandler (CONST HTTPServerRequest and notUsed) {Return New MyRequestHandler; }}; The 'notUsed' variable ... has not been used so you ask, why is there any logic? Because this base class is overriding the declared function in HTTPRequestHandlerFactory, this function will have the argument const HTTPServerRequest and , so it should also appear in the function that overrides the derived class (although it has not been used ). If the 'not used' is used in the createRequestHandler () function, then const keyword ensures that it has createRequestHandler () Can not be changed inside.
Comments
Post a Comment