473,748 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Putting implmentation in .h files?

Hi,

Can you please tell me what is the guideline in Putting implmentation
in .h files?
I see examples where they put the implementation of getter/setting in
the .h files where funcitons is > 10 lines of code are put in .cpp
file.

Is that the guideline?

Thank you.

Feb 26 '06 #1
17 1804
Hello!

I see two cases as to where you put the implementation in .h file:
1. When you have a template class and you don't want to mess with pImpl
stuff.
2. When you have really small and calling very often functions that you
will put into a declaration of class. Please, consider that every
function that is in decl. of class is automaticallly an inline.

class foo
{
public:
int bar(); //declared somewhere else
void haha() //this is automatically inline
{
//some small code
}
};

Feb 26 '06 #2
Normally the decleraions are made in the header files and implentaions
are in cpp file. But templates should be declared and implement in the
header file itself.

Feb 26 '06 #3
Backer wrote:
Normally the decleraions are made in the header files and implentaions
are in cpp file. But templates should be declared and implement in the
header file itself.


.... or you hide away the implementation of a template's declarations in
a separate .inl file and include it with a last statement in the
template's header. So, you can emulate separation of interface and
implementation details for templates - an approach I usually prefer and
recommend.

Greets
Feb 26 '06 #4

Backer wrote:
Normally the decleraions are made in the header files and implentaions
are in cpp file. But templates should be declared and implement in the
header file itself.


.... or you could use the pImpl idiom like Boost-developers.

Feb 26 '06 #5
<OT>

Alex Beluga wrote:
[snip]

class foo
{
public:
int bar(); //declared somewhere else
void haha() //this is automatically inline
{
//some small code
}
};


I was amused a few days ago, when I found out, that metasyntactic
variables have been mentioned even in RFC (RFC 3092, it's dated 1st
April 2001; coincidence? :o) )

They list "standard" metasyntactic variables in the order they "should"
be used in code examples: foo, bar, baz, qux, quux, corge, grault,
garply, waldo, fred, plugh, xyzzy, thud.

So, correctly, your example should go like this:

class foo
{
public:
int bar(); //declared somewhere else
void baz() //this is automatically inline
{
//some small code
}
};

;o)

</OT>
Feb 26 '06 #6
Thanks a lot! I think we should post this request in the neighbourly
residing comp.std.c++ or at least try to push it into Boost.

8-)

Feb 26 '06 #7
On Sun, 26 Feb 2006 12:05:25 +0100, Stephan Rupp
<al****@tu-harburg.de> wrote:
... or you hide away the implementation of a template's declarations in
a separate .inl file and include it with a last statement in the
template's header. So, you can emulate separation of interface and
implementati on details for templates - an approach I usually prefer and
recommend.


Your approach may be usful but it neither hides the implementation of
templates nor emulates the separation of interface and implementation
for templates.

Best wishes,
Roland Pibinger
Feb 26 '06 #8
Pl********@gmai l.com wrote:
Hi,

Can you please tell me what is the guideline in Putting implmentation
in .h files?
I see examples where they put the implementation of getter/setting in
the .h files where funcitons is > 10 lines of code are put in .cpp
file.

Is that the guideline?


There is no universal guideline. It all depends on the project and the
community/culture. The technical reason for separating interface and
implementation is to ease separate compilation, which reduces build times
in large projects. For small projects, I do not see a technically
compelling reason at all to separate definition and declaration. From a
programmers point of view, the only reasons that remain are about meeting
the reasonable expectations regarding code layout of your fellow
programmers and your future self. Those expectations tend to vary from
project to project.
Best

Kai-Uwe Bux

Feb 26 '06 #9
Hello

What's pImpl stuff?

Thanks.

Feb 26 '06 #10

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

Similar topics

4
3236
by: Eric Kincl | last post by:
Hello, its been a while since I posted/looked here... my normal email client doesn't handle newsgroups :( (ximian evolution) I was wondering how you stick a file into a database, and then retrive it again for the user with PHP/MySQL. I tried the following which apparently didnt work... Very quick overview of what I did... html
1
1621
by: Christopher M. Lusardi | last post by:
Hello, I have a program that can be compiled and run on SGI and Linux computers, and only one of the files in the program has is different. On the SGI system, the file has a dot capital C suffix, and on Linux it has a dot lower case c suffix. When I put both files in one file and surround them with precompiler directives such as #if SGI ... #elif LINUX ... #endif, the compiler complains when it includes other files. How can I get it...
0
932
by: Alexey Zhilenko | last post by:
I have to perform this operation: Getting and putting files onto virtual folder on WEB site programmatically. Please advise me which component to use. Thank you.
1
1282
by: Davy Marichael | last post by:
Hello, i'm working with ASP.NET to create my aspx files, the program i've made communicates with a Db (oledb) to read data and to write data.. I've found a server that supports asp,php, mysql,... http://ibizaaaaaaah.europe.webmatrixhosting.net/Login.aspx The login and paswd are; Ibiza, Steamy
3
1576
by: Asfand Yar Qazi | last post by:
For years, I've been putting everything that won't be needed outside a compilation unit in anonymous namespaces, even editing my old files that did things the 'old' way (using static linkage). Then suddenly I find this in the KDE developer faq: Q: 2.24. I put some functions in anonymous namespace and someone reverted it and made those functions static, why? Symbols defined in a C++ anonymous namespace do NOT have internal linkage....
3
1163
by: Kenneth McDonald | last post by:
Over the last couple of years, I've built a module called rex that lays on top of (and from the user's point of view, hides) the re module. rex offers the following advantages over re. * Construction of re's is object oriented, and does not require any knowledge of re syntax. * rex is _very good_ at combining small re's into larger re's. In fact, this sort of composition is almost effortless. It greatly simplifies the creation of...
0
2194
by: Anish G | last post by:
Hi, I have an issue with reading CSV files. I am to reading CSV file and putting it in a Datatable in C#. I am using a regular expression to read the values. Below is the code. Now, it reads CSV file without any issues only if all the fields are not null. If any field is blank, it moves the values to the left and displays the value under invalid column. Example is shown below: A part of CSV file. I am reading the first row as...
0
2409
by: drawing in aspnet | last post by:
Question about putting the data layer in a separate class library. I keep reading that the data layer should be separated from the presentation layer and put in its own class library. I am trying to do this but running into a problem. I'm hoping someone can point me in the right direction. I first create a class library (all code in C#) and within this class library create a very simple Sql Server Express database (.mdb) file. It's...
2
1950
by: niskin | last post by:
I'm trying to create a file called retrieve.vbs with my program and it creates this file, with all the necessary code for the file to run, but the part that relies on user input does not get written properly. In my program the user inputs the name of the computer they want to connect to and I need to use that variable in my script. The name of the computer I trying to connect to when I test my program is ADMIN-PC. Once my program has created the...
0
8995
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
8832
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
9561
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...
0
9381
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
9332
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
8252
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...
1
6799
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
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.