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

What goes where in which files

Ok, I'm just checking i'm on the right lines:
sorry if i make a mistake with any strict definitions of things

in a .h , try and put:

class declaration (prototype)
relevant forward declarations for pointers in the class,
#includes required for the objects aggregated in the class
#includes required for base-classes
#includes for templates

in .cpp we put:

class definition
#includes to resolve the forward declarations in the .h if the pointer
declarations are used.
#defines for class

Where do the namespace 'definitions' go, I've been putting them around both
files
Also where to globals go, I would have though the .h with Guard headers?

Thanks Mike


Jul 22 '05 #1
1 1286
"Michael" <sl***********@hotmail.com> wrote:
Ok, I'm just checking i'm on the right lines:
sorry if i make a mistake with any strict definitions of things
From "The C++ Programming Language" 3rd Ed by Bjarne Stroustrup

"""
As a rule of thumb, a header may contain:

Named namespaces: namespace N { /*...*/ }
Type definitions: struct Point { intx, y; };
Template declarations: template< typename T > class Z;
Template definitions: template< typename T > class V { /*...* }
Function declarations: extern int strlen( const char* );
Inline function definitions: inline char get(char* p) { return *p++; }
Data declarations: extern int a;
Constant definitions: const float pi = 3.141593;
Enumerations: enum Light { red, yellow, green };
Name declarations: class Matrix;
Include directives: #include <algorithm>
Macro definitions: #define VERSION 12
Conditional compilation directives: #ifdef __cplusplus
Comments: /* check for end of file */

Conversly a header should never contain:

Ordinary function definitions: char get(char* p) { return *p++ };
Data definitions: int a;
Aggregate definitions: short tbl[] = {1, 2, 3};
Unnamed namespaces: namespace { }
Exported template definitions: export template<class T>f(T t){ /*...*/}
"""

I include global using directives and declarations in the "should never
contain" list.

Where do the namespace 'definitions' go, I've been putting them around both
files
I'm not sure what you mean by namespace 'definitions', but the answer
should be in the above.
Also where to globals go, I would have though the .h with Guard headers?


The declaration part of the global goes in the header (and can be in
more than one header as long as they are all the same,) the definition
of the global goes in *one* cpp file.
Jul 22 '05 #2

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

Similar topics

21
by: godwin | last post by:
Hi all, I wanna thank Martin for helping out with my ignorance concerning execution of stored procedure with python. Now i have decided to write a web app that googles into my companies...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
22
by: MLH | last post by:
I have some audio help files that play fine from within Access 97 and Access 2.0. Both are running on a Windows XP box. But I do not know what program plays the files. If I click Start, Run and...
1
by: Bruce W.1 | last post by:
I'm storing some things in the application state, like this: Application = "whatever"; In Visual Studio, when I shut down the web app then start it again the application state information...
6
by: EMW | last post by:
I have finished my web application in ASPX, but HOW do I put WHAT on the server to be able to run the site? I upload the files to a remote server, so I can't do it with a setup file. rg. Eric
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
22
by: MarkusR | last post by:
I am currently using StarTeam for my source control. (Will eventual switch to whatever the latest Visual Source Safe is going to be called). With debug, installers, deploy and everything the...
7
by: mosfet | last post by:
HI, when trying to compile an embedded version of STL called ustl on win32 platform I get the following error : /// Returns the minimum of \p a and \p b template <typename T1, typename T2>...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...

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.