473,387 Members | 1,532 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,387 software developers and data experts.

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 2617
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
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....
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
21
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...
3
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...
5
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...
7
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...
6
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...
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...
7
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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.