473,806 Members | 2,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inline class functions in separate file

Hello,

I have been going through several header source files which define
classes with inline functions. In the case where the inline functions
are not defined in place, the inline functions from all classes within
the header file are included via a separate file, at the end of the
file, with a directive of the form:

#include <foo.inl>

Could anyone explain what the reason could be for separating the
inline functions into a separate file in this way?

Thanks,

JG

Oct 30 '06 #1
4 2643
John Goche wrote:
Hello,

I have been going through several header source files which define
classes with inline functions. In the case where the inline functions
are not defined in place, the inline functions from all classes within
the header file are included via a separate file, at the end of the
file, with a directive of the form:

#include <foo.inl>

Could anyone explain what the reason could be for separating the
inline functions into a separate file in this way?
It's probably due to the lack of the export keyword. See this FAQ:

http://www.parashift.com/c++-faq-lit...html#faq-35.13

Cheers! --M

Oct 30 '06 #2
mlimber wrote:
John Goche wrote:
Hello,

I have been going through several header source files which define
classes with inline functions. In the case where the inline functions
are not defined in place, the inline functions from all classes within
the header file are included via a separate file, at the end of the
file, with a directive of the form:

#include <foo.inl>

Could anyone explain what the reason could be for separating the
inline functions into a separate file in this way?

It's probably due to the lack of the export keyword. See this FAQ:

http://www.parashift.com/c++-faq-lit...html#faq-35.13
The 'export' keyword has nothing to do with inline functions. Inline
functions obviously have to be fully defined (not just declared) at
compile time instead of linking time, because the intent is to insert
the code of the function directly where the call is made (*). That's
why we make the definition visible to the compiler through an #include
directive.

(*) The compiler has a veto on whether this really happens or not, but
the requirement still holds nonetheless.

Regards,
Bart.

Oct 30 '06 #3
John Goche wrote:
I have been going through several header source files which define
classes with inline functions. In the case where the inline functions
are not defined in place, the inline functions from all classes within
the header file are included via a separate file, at the end of the
file, with a directive of the form:

#include <foo.inl>

Could anyone explain what the reason could be for separating the
inline functions into a separate file in this way?
A possible reason is that the authors want to keep open the posibility to
drop the inlines and separately compile the implementation of the files,
and they want to be able to make the change with a minimal edition.

They can have guidelines, or automated documentation tools, that considers
that all the contents of header files is public API, and the .inl are not.

They can want to separate the #include required for the class declaration
from those used by the implemantation, and consider that the separation in
two files is the clearer way to do it.

The reason can simply be "In this company we do it that way from some years
ago, nobody remember the rationale and nobody want to take the work to redo
the style guides".

To know the real reason in each case, you must ask the authors.

--
Salu2
Oct 30 '06 #4
Bart wrote:
mlimber wrote:
John Goche wrote:
Hello,
>
I have been going through several header source files which define
classes with inline functions. In the case where the inline functions
are not defined in place, the inline functions from all classes within
the header file are included via a separate file, at the end of the
file, with a directive of the form:
>
#include <foo.inl>
>
Could anyone explain what the reason could be for separating the
inline functions into a separate file in this way?
It's probably due to the lack of the export keyword. See this FAQ:

http://www.parashift.com/c++-faq-lit...html#faq-35.13

The 'export' keyword has nothing to do with inline functions. Inline
functions obviously have to be fully defined (not just declared) at
compile time instead of linking time, because the intent is to insert
the code of the function directly where the call is made (*). That's
why we make the definition visible to the compiler through an #include
directive.

(*) The compiler has a veto on whether this really happens or not, but
the requirement still holds nonetheless.
Boy, I'm just not having a good day at reading posts correctly. You are
right about the inline business, but absent any actual code, my
comments about export may also apply. Additionally, it strikes me that
the OP may be asking why functions would not be defined within the
class. That may just be a stylistic issue in the case of non-template
functions (e.g., the author wants to emphasize the public interface
rather than its implementation) , but in the case of template functions,
it may also be because of specialization.

Cheers! --M

Oct 30 '06 #5

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

Similar topics

13
6577
by: A | last post by:
Hi, I'm having problems completing a project in C++. I have been using inline functions in some of my header files. I have only done so for simple functions that only have 1 statement (eg. accessor and mutator methods to access private data members). I would like to know if there are any issues with using inline functions that may have attributed to my errors before I start separting them out into "outline functions". Regards
47
3888
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
21
746
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've read many authors (and it's my belief, too) who discourage the use of the 'inline' keyword, because: - The 'inline' word only advice the compiler about wich functions should be expanded, but not force it to expand them. Also, the compiler can...
3
1357
by: Peng Yu | last post by:
Hi, I'm trying to define inline_test::test() to be inline. But I always got errors. I know that if I define inline_test::test() in inline_test.h, there are no errors. But I still would rather to put the member functions in *.cc files not the *.h files. Do you know how to do that? The following paragraphs are the compile error and the source codes.
5
1543
by: Per | last post by:
Hi I am currently working on a mathlib and I want maximum performance (speed). If I delcare a function in the mathlib inline will the user apps take advantage of that or will it be called as regular function? So will a inline function from a lib file really be inline when I use it in different apps. ? /p
7
2864
by: Srini | last post by:
Hello, Rules for inline functions say that they have to be defined in the same compilation unit as their declarations. For class member functions this means that the inline member functions must be defined either within the class or within the same header file. But its generally a good programming practice to have the declarations and definitions in seperate files. This would make the future maintenance of the code easier.
6
2458
by: John Ratliff | last post by:
I was reading the C++ FAQ Lite about inline functions, and it says the following (http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.7) " It's usually imperative that the function's definition (the part between the {...}) be placed in a header file. If you put the inline function's definition into a .cpp file, and if it is called from some other .cpp file, you'll get an "unresolved external" error from the linker. " Why...
6
4009
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
7
16135
by: Wu Shaohua | last post by:
Hi Guys, 1. As we know usually we should not define a constructor as inline. I also learned if we define a member function inside the class this member function will be automatically be inline'ed. My question is: If I define a constructor (including its body) or another large member function inside the class, the constructor or the member function is inline or not? why? 2. I learned that if the member function is big we should not...
0
9719
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
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10372
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
10110
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...
0
9187
agi2029
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...
0
6877
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();...
0
5546
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...
1
4329
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
3
3008
bsmnconsultancy
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...

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.