473,770 Members | 3,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inline virtual functions.

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 I've never used one. ( I'm an experienced software developer
and have used C++ for more than 10 years)

Anybody found the use of one of these guys necessary or useful.
Curious minds need to know for the next curve ball question coming my
way....!

thanks, dave
Jul 22 '05 #1
15 10642
"Dave Townsend" <da********@com cast.net> wrote...
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 I've never used one. ( I'm an experienced software developer
and have used C++ for more than 10 years)

Anybody found the use of one of these guys necessary or useful.
Curious minds need to know for the next curve ball question coming my
way....!


I am not sure I understand the reason for your puzzlement with those
functions. First of all, 'inline' is not a real attribute of
a function, but a mere suggestion. Second, any function that is
defined in the class definition is implicitly 'inline'. Third,
a virtuality of a function and its 'inline-ness' are two completely
orthogonal qualities, there is nothing special about them coexisting
just like 'const' and 'virtual' or 'const' and 'inline'.

So, I bet during your 10 years you have written something like

class Base {
public:
virtual ~Base() {} // does nothing -- no data
virtual void someFoo() = 0;
virtual void someBar() const = 0;
};

and suddenly you have the destructor for 'Base' defined as (gasp!)
inline and virtual. Ah, that's what "inline virtual" functions look
like! And I've been using those all the time without even knowing
that...

Come on, give yourself a break. Interviews (if you don't do them on
a regular basis) are stressful and some people can even forget the
multiplication table, let alone inline virtual functions.

Victor
Jul 22 '05 #2
"Dave Townsend" <da********@com cast.net> wrote in message
news:LK******** ************@co mcast.com
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 I've never used one. ( I'm an experienced software developer
and have used C++ for more than 10 years)

Anybody found the use of one of these guys necessary or useful.
Curious minds need to know for the next curve ball question coming my
way....!

thanks, dave

I think this was a trick question. Virtual function calls are only resolved
at runtime and cannot be inlined. The qualification to this statement is
that if a virtual function is called directly (i.e., using a class object
rather than a pointer or reference or else using the scope resolution
operator to fully specify the function concerned), then it is non-virtual
for the purposes of that call and can be inlined.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 22 '05 #3
Dave Townsend wrote:

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 I've never used one. ( I'm an experienced software developer
and have used C++ for more than 10 years)

Anybody found the use of one of these guys necessary or useful.
Curious minds need to know for the next curve ball question coming my
way....!


The compiler can't [always] know for certain which virtual will be
called.. therefore it cannot inline the function as it [often] must be
bound at runtime [via vtable lookup].

struct Base
{
virtual void Blah() { ; }
};

struct Sub: Base
{
/*virtual*/ void Blah() { ; }
};

void SomeFunc( Base* obj )
{
obj->Blah(); // impossible to know which function to inline here!
}
There are of course cases when the compiler can determine which function
needs to be called, and might therefore inline it. I don't know for
certain what the popular compilers do in this case. Once such case:

void OtherFunc()
{
Sub s;
s.Blah(); // always inlinable
}

So, while it shouldn't hurt anything, it probably also won't usually get
inlined.

Also remember that the inline function-specifier (implicit or explicit)
is only a recommendation.

See 7.1.2.

--Steve
Jul 22 '05 #4

"Stephen Waits" <st***@waits.ne t> wrote in message
news:40******** ******@waits.ne t...

Also remember that the inline function-specifier (implicit or explicit)
is only a recommendation.

See 7.1.2.


However, inline has a second meaning as a linkage directive!

If you define a function in a header file (not a practice I would
recommend, but for the sake of argument), then only one file
in a multiple source file project may include that header, unless
the definition is tagged as inline. Failing to do that, ambiguities
in name resolution will emerge at link time.

- Risto -
Jul 22 '05 #5
"John Carson" <do***********@ datafast.net.au > wrote in message news:<40******* *@usenet.per.pa radox.net.au>.. .
"Dave Townsend" <da********@com cast.net> wrote in message
news:LK******** ************@co mcast.com
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 I've never used one. ( I'm an experienced software developer
and have used C++ for more than 10 years)

Anybody found the use of one of these guys necessary or useful.
Curious minds need to know for the next curve ball question coming my
way....!

thanks, dave

I think this was a trick question. Virtual function calls are only resolved
at runtime and cannot be inlined. The qualification to this statement is
that if a virtual function is called directly (i.e., using a class object
rather than a pointer or reference or else using the scope resolution
operator to fully specify the function concerned), then it is non-virtual
for the purposes of that call and can be inlined.


Of course, this is not the typical way to call such a function. It smells of
either a questionable design or a performance hack.

There is one exception, though. There is one quite common use of this
mechanism: If the derived class version of a virtual function is supposed
to call the base class version. An example would be a print function where
each derived class adds print statements for its own data.
Jul 22 '05 #6
* "John Carson" <do***********@ datafast.net.au > schriebt:
"Dave Townsend" <da********@com cast.net> wrote in message
news:LK******** ************@co mcast.com
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 I've never used one. ( I'm an experienced software developer
and have used C++ for more than 10 years)

Anybody found the use of one of these guys necessary or useful.
Curious minds need to know for the next curve ball question coming my
way....!


I think this was a trick question. Virtual function calls are only resolved
at runtime and cannot be inlined. The qualification to this statement is
that if a virtual function is called directly (i.e., using a class object
rather than a pointer or reference or else using the scope resolution
operator to fully specify the function concerned), then it is non-virtual
for the purposes of that call and can be inlined.


The question was about inline virtual functions, not about inlining of virtual
function calls or of calls of virtual functions.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #7
"Alf P. Steinbach" <al***@start.no > wrote in message
news:40******** ********@news.i ndividual.net

The question was about inline virtual functions, not about inlining
of virtual function calls or of calls of virtual functions.


And why do you think that the interviewer bothered to single out inline
virtual functions as opposed to inline functions in general? The only reason
that I can think of is because the rules for inlining are different.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 22 '05 #8
* "John Carson" <do***********@ datafast.net.au > schriebt:
"Alf P. Steinbach" <al***@start.no > wrote in message
news:40******** ********@news.i ndividual.net

The question was about inline virtual functions, not about inlining
of virtual function calls or of calls of virtual functions.


And why do you think that the interviewer bothered to single out inline
virtual functions as opposed to inline functions in general? The only reason
that I can think of is because the rules for inlining are different.


It was an open question.

An open question can tell much.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #9
How about this.

<Foo.h>
Class Foo
{
public:
virtual void func() {}
}

<Bar.h>
#include "Foo.h"
class Bar : public Foo
{
public:
virtual void func();
}

<Bar.cpp>
void Bar::func()
{
}

<Main.cpp>

#include "Foo.h"
#include "Bar.h"

int main()
{
Foo f;
Bar b;

f.func(); // can be resolved at compile time.and is inlined
b.func(); // can be resolved at compile time and is outlined

Foo* fb = new Bar;
fb->func(); // resolved at runtime.

return 1;
}

Jul 22 '05 #10

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

Similar topics

20
5997
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"; } // Other members
6
322
by: puzzlecracker | last post by:
Is there a case where having an "inline function" is more effective and less code i.e. code clean, but we still resort to use a regular function for this purpose? Another question, which I previously posted but answers were very opinioned and not conclusive - Likely due to somewhat ambiguous description in the first place. Sorry for repost!
43
13306
by: Patrick Laurent | last post by:
Hello I have a program with many many inlined template functions It is essential for the execution speed that every (or almost every) function marked as inlined, becomes really inlined by the compiler. I already compiled the program with Intel Compiler (ICL) on Visual C++, and it works fine and fast. I verified that the functions are really inlined. But with GCC 3.4 (Linux+Cygwin) or ICC (Linux), The same program is about 5
6
4008
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 as well. To support thin-template, I need to make virtual function as inline. Now, I know that compiler would generate an out-of-line copy when it
8
3006
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 at compile time about the actual object a pointer points to so that it can paste the correct inline function in the place of function call if the function is getting inlined?
0
9602
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10071
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.