![]() |
inline+virtual
Hello,
I have a class deriving from a class that provides ability to serialize/deserialize objects over the network. There are two classes Requests (sent from client to server) Response(sent from server to client), these two classes need to implement a pure virtual method called dispatch(), however only client needs to implement Response::dispatch() and only server needs to implement Request::dispatch(). I am planning to build a library from these two classes and client/server will link in this library. The goal is that server when linked should not see concrete implementation for Response::dispatch() as it will contain calls to client specific code , vice versa (will cause bad link errors when building my client/ server tasks). I am constrained to use the class that provides serialization/deserialization infrastructure. The only way I could think of getting around this problem is to provide: -Request.h that specifies complete interface and Request.cpp that provides implementation only for functions common to client/server (like getters/setters for formulating req/resp) -Request_server.h that includes Request.h and provides inline implementation for dispatch() function that contains calls to server specific code (included in server) -Request_client.h that includes Request.h and provides inline NO-OP implementation for dispatch() . (included in client) However since dispatch() is virtual it cannot be inlined (inline=compile time, viritual=runtime orthogonal to each other). The only workaround I can think of was to implement dispatch() by calling non-virtual function called dispatchRequest(), and implement dispatchRequest() as no-op inline function in Request_client.h and as acutal function with code in Request_server.h. Is this correct solution to the problem? Thanks |
Re: inline+virtual
sunil wrote:
> I have a class deriving from a class that provides ability to > serialize/deserialize objects over the network. There are two classes > Requests (sent from client to server) Response(sent from server to > client), these two classes need to implement a pure virtual method > called dispatch(), I doubt that; pull the dispatch() out of the message type objects and into something that manages those messages (a message queue on the server side, or whatever.) |
Re: inline+virtual
On Aug 26, 1:56*pm, Matthias Buelow <m...@incubus.de> wrote:
> sunil wrote: > > *I have a class deriving from a class that provides ability to > > serialize/deserialize objects over the network. *There are two classes > > Requests (sent from client to server) Response(sent from server to > > client), these two classes need to implement a pure virtual method > > called dispatch(), > > I doubt that; pull the dispatch() out of the message type objects and > into something that manages those messages (a message queue on the > server side, or whatever.) I cannot do that since I am using an existing library that provides this functionality for serialization of objects |
Re: inline+virtual
On Aug 26, 10:03*am, sunil <sunilsreenivas2...@yahoo.com> wrote:
> *However since dispatch() is virtual it cannot be inlined > (inline=compile time, viritual=runtime orthogonal to each other). The > only workaround I can think of was to implement dispatch() by calling > non-virtual function called dispatchRequest(), and implement > dispatchRequest() as no-op inline function in Request_client.h and as > acutal function with code in Request_server.h. Is this correct > solution to the problem? I don't see any problem that exists here. As you point out, "inline' and "virtual" are orthogonal, - meaning that each specifier has no effect on the other. In fact, there is nothing in C++ that prevents a virtual method from being declared inline, and no reason why a C++ program should avoid declaring such a method. Greg |
Re: inline+virtual
On Aug 26, 5:37*pm, Greg Herlihy <gre...@mac.com> wrote:
> On Aug 26, 10:03*am, sunil <sunilsreenivas2...@yahoo.com> wrote: > > > *However since dispatch() is virtual it cannot be inlined > > (inline=compile time, viritual=runtime orthogonal to each other). The > > only workaround I can think of was to implement dispatch() by calling > > non-virtual function called dispatchRequest(), and implement > > dispatchRequest() as no-op inline function in Request_client.h and as > > acutal function with code in Request_server.h. Is this correct > > solution to the problem? > > I don't see any problem that exists here. As you point out, "inline' > and "virtual" are orthogonal, - meaning that each specifier has no > effect on the other. In fact, there is nothing in C++ that prevents a > virtual method from being declared inline, and no reason why a C++ > program should avoid declaring such a method. > > Greg what I mean by orthogonal is that they dont make sense together for inlines code get replaced at compile time for virtual the call happens at runtime thru virtual table, so if you define a virutal function as inline and you try to call it thru base pointer it wont work since compiler wouldnt know what function to call (since its inlined, the function wont exist in compiled code) |
| All times are GMT. The time now is 11:01 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.