473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Aug 26 '08 #1
5 1895
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.)
Aug 26 '08 #2
On Aug 26, 1:56*pm, Matthias Buelow <m...@incubus.dewrote:
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
Aug 26 '08 #3
On Aug 26, 10:03*am, sunil <sunilsreenivas2...@yahoo.comwrote:
*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

Aug 26 '08 #4
On Aug 26, 5:37*pm, Greg Herlihy <gre...@mac.comwrote:
On Aug 26, 10:03*am, sunil <sunilsreenivas2...@yahoo.comwrote:
*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)
Aug 27 '08 #5
On 2008-08-27 15:28:42 -0400, sunil <su****************@yahoo.comsaid:
>
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)
But it will. The compiler has to do the right thing. It can generate
the code inline when it's appropriate, and it must provide a definition
for use in a virtual call.

struct Base
{
inline virtual void f();
};

struct Derived : Base
{
inline virtual void f() { ... }
};

void g(Base& bb)
{
Base b;
b.f(); // calls B::f; can be inlined
Derived d;
d.f(); // Calls D::f; can be inlined
bb.f(); // Don't know what it calls; can't be inlined
}

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Aug 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: qazmlp | last post by:
My class in a header file, contains inline virtual destructor. Is this Ok? Can it cause any problems? class base { public: base() { } virtual ~base { std::cout<<"Inside virtual destructor\n";...
15
by: Dave Townsend | last post by:
Yo, I had a job interview today, the interviewing asked me about inline virtual functions, or what was my opinion on them. Hm, I've seen mention of these babies in the reference material, but...
6
by: RainBow | last post by:
Greetings!! I introduced the so-called "thin-template" pattern for controlling the code bloat caused due to template usage. However, one of the functions in the template happens to be virtual...
3
by: shuisheng | last post by:
Dear All, If I define a virtual function to be inline, is it really inline? Or it is inline in some cases, and not in other cases. Would you please help me to look at the following case. ...
8
by: siddhu | last post by:
Dear experts, A virtual function has to have an address. So if an inline virtual function is actually inlined then in that case what does address of this function signify? How does compiler know...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.