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<<"Ins ide virtual destructor\n"; }
// Other members
}; 20 5978
"qazmlp" <qa********@red iffmail.com> wrote in message
news:db******** *************** ***@posting.goo gle.com... 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<<"Ins ide virtual destructor\n"; }
// Other members };
It's fine, in fact its common. Why shouldn't it be OK?
john
qazmlp wrote: 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<<"Ins ide virtual destructor\n"; }
// Other members };
If you declare a function as inline it doesn't mean that the compiler
*has* to inline that code - which usually wouldn't work with virtual
functions - you just 'suggest' that he *could* inline it. So it's all
right with that...
qazmlp wrote: My class in a header file, contains inline virtual destructor. Is this Ok? Can it cause any problems?
It can't. What excactly makes you to worry about it?
--
Best regards,
Andrey Tarasevich
"John Harrison" <jo************ *@hotmail.com> wrote in message
news:c1******** *****@ID-196037.news.uni-berlin.de... "qazmlp" <qa********@red iffmail.com> wrote in message news:db******** *************** ***@posting.goo gle.com... 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<<"Ins ide virtual destructor\n"; }
// Other members };
It's fine, in fact its common. Why shouldn't it be OK?
Because it's "inline" and it's also "virtual". You don't see why that might
be contradictory and confusing?
jeffc wrote: > 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<<"Ins ide virtual destructor\n"; } > > // Other members > };
It's fine, in fact its common. Why shouldn't it be OK?
Because it's "inline" and it's also "virtual". You don't see why that might be contradictory and confusing? ...
It shouldn't be contradictory and/or confusing to a person who fully
understands the meaning of these qualifiers in C++.
--
Best regards,
Andrey Tarasevich
"jeffc" <no****@nowhere .com> wrote 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<<"Ins ide virtual destructor\n"; }
// Other members };
It's fine, in fact its common. Why shouldn't it be OK?
Because it's "inline" and it's also "virtual". You don't see why that might be contradictory and confusing?
Virtual functions can be inlined. The compiler can determine by context whether
to inline the code or do a polymorphic call. For example, if you invoke a
virtual method directly on an object (not a reference or a pointer), the
compiler MAY choose to inline the code, since there's no ambiguity. Or it can
make a direct (non-vtable) call to the out-of-line function. If you're calling
the same virtual function through a pointer or a reference, the compiler must
then select the appropriate function through the vtable. This implies that you
may (and probably will) have both an out-of-line and inline implementations of
your function if (a) it's inlineable, and (b) you call it directly at some
point.
A detail to remember: when you invoke a method from within the object, it's
invoked through the 'this' pointer, which means that unless you qualify it, you
always get a polymorphic call.
Claudio Puviani
"Andrey Tarasevich" <an************ **@hotmail.com> wrote in message
news:Jd******** ************@co mcast.com... jeffc wrote: > 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<<"Ins ide virtual destructor\n"; } > > // Other members > };
It's fine, in fact its common. Why shouldn't it be OK?
Because it's "inline" and it's also "virtual". You don't see why that
might be contradictory and confusing? ...
It shouldn't be contradictory and/or confusing to a person who fully understands the meaning of these qualifiers in C++.
It seems to be a very common misunderstandin g that the meaning of the
keyword inline has something to do with inlining function calls (easy to see
how that misunderstandin g would occur). However the only meaning that the
C++ standard gives to inline functions is as an exception to the one
definition rule, thereby allowing inline functions to usefully appear in
header files.
In any case there are cases where a virtual function is called via a
non-virtual mechanism, this is especially true of a destructor.
john
"Andrey Tarasevich" <an************ **@hotmail.com> wrote in message
news:Jd******** ************@co mcast.com... It's fine, in fact its common. Why shouldn't it be OK?
Because it's "inline" and it's also "virtual". You don't see why that
might be contradictory and confusing? ...
It shouldn't be contradictory and/or confusing to a person who fully understands the meaning of these qualifiers in C++.
Use your head man - does the originator of this thread sound like someone
who "fully understands the meaning of these qualifiers in C++"?
"John Harrison" <jo************ *@hotmail.com> wrote: It seems to be a very common misunderstandin g that the meaning of
the keyword inline has something to do with inlining function calls
(easy to see how that misunderstandin g would occur). However the only meaning
that the C++ standard gives to inline functions is as an exception to the one definition rule, thereby allowing inline functions to usefully
appear in header files.
It does have 'something to do' with inlining function calls:
"The inline specifier indicates to the implementation that inline
substitution of the function body at the point of call is to be
preferred to the usual function call mechanism." (7.1.2)
Inlining is not required, as you know, but it's a bit of an
overstatement to say that 'inline' is completely unrelated to
inlining.
Jonathan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 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
|
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
|
by: pmizzi |
last post by:
When i compile my program with the -ansi -Wall -pedantic
flags,
i get this warning: `class vechile' has virtual functions
but non-virtual destructor, and the same with my
sub-classes. But when i add a virtual destructor like this :
" virtual ~vechile". I get this error:
Undefined first referenced
symbol in file
vtable for vechile /var/tmp//ccC9yD6Z.o
|
by: John Ratliff |
last post by:
Can the compiler ever inline a method when there is a pointer to the
member used?
Thanks,
--John Ratliff
|
by: mark |
last post by:
I have this class:
class Selections {
OSStatus Init();
protected:
CFMutableSetRef selectionObjects;
static void CFASelectionsApplier(const void* value, void* ctx);
OSType ready;
public:
Selections();
| |
by: Alden Pierre |
last post by:
Hello,
http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.7
As per the link above it's wise to have a virtual deconstructor when
creating an abstract class. Here is when I'm little confused. Am I
deleting the right object when I call the virtual deconstructor? I was
under impression when creating a class if I'm not specifically
allocating memory, do not implement deconstructor and let the default
take care of it...
|
by: druberego |
last post by:
I read google and tried to find the solution myself. YES I do know that
you can get undefined references if you:
a) forget to implement the code for a prototype/header file item, or
b) you forget to pass all the necessary object files to the linker.
Neither of those are my problem. Please bear with me as the question
I ask is rather long and I think it's beyond a CS101 level of linker
stupidity. If it is a stupid CS101 mistake I'm making...
|
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?
|
by: Tonni Tielens |
last post by:
I'm trying to create a pure virtual class describing an interface.
Normally, when I do this I make the destructor pure virtual so that,
even if there are no members in the class, it cannot be instantiated.
The difference now is that I'm making a generic interface with
template arguments. Template classes should be defined in the header
file, but it is not allowed for a destructor's definition to be in the
class definition if the...
|
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...
|
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,...
| |
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |