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

multiple definition

Hi everybody!

I have a question concerning code organisation. Suppose I have the following
header file:

#ifndef SOME_NAME
#define SOME_NAME

namespace N {
void F()

... here comes the implementation
}
}

#endif

In this case I would think that you never ever can encounter a 'multiple
definition' problem because
1) SOME_NAME is defined the first time F is defined
2) there is only one definition of F, so it even wouldn't be a problem to
define the same F a hundred times...

Still, I get the error message that F is multiply defined when this header
file is used in other header files. (And there is definitely not another 'F'
defined in any of these header files)

Can anyone help me out?

Thanks!

Jochen
Jul 19 '05 #1
2 21005

"Jochen Zeischka" <jo*************@rug.ac.be> wrote in message
news:bd**********@gaudi2.UGent.be...
Hi everybody!

I have a question concerning code organisation. Suppose I have the following header file:

#ifndef SOME_NAME
#define SOME_NAME

namespace N {
void F()

... here comes the implementation
}
}

#endif

In this case I would think that you never ever can encounter a 'multiple
definition' problem because
1) SOME_NAME is defined the first time F is defined
2) there is only one definition of F, so it even wouldn't be a problem to define the same F a hundred times...

Still, I get the error message that F is multiply defined when this header
file is used in other header files. (And there is definitely not another 'F' defined in any of these header files)

Can anyone help me out?

Thanks!

Jochen


Please note that the header guards protect multiple inclusion of a header
file in
a single translation unit(e.g.cpp file). If you happen to include this
header file in several
translation units then the linker problem will arise. Either move the
definition to some implementation file or
else make the function inline(only if it suits in your case) .

Jul 19 '05 #2

"Jochen Zeischka" <jo*************@rug.ac.be> wrote in message
news:bd**********@gaudi2.UGent.be...
Hi everybody!

I have a question concerning code organisation. Suppose I have the following header file:

#ifndef SOME_NAME
#define SOME_NAME

namespace N {
void F()

... here comes the implementation
}
}

#endif

In this case I would think that you never ever can encounter a 'multiple
definition' problem because
1) SOME_NAME is defined the first time F is defined
2) there is only one definition of F, so it even wouldn't be a problem to define the same F a hundred times...

Still, I get the error message that F is multiply defined when this header
file is used in other header files. (And there is definitely not another 'F' defined in any of these header files)

Can anyone help me out?

Thanks!

Jochen

I had the same problem. I solved it by splitting the code into two: the
declarations in a .h file and _all_ the implementations in a .cpp file, i.e.
// foo.h
#ifndef foo_h
#define foo_h

namespace n
{
class bar
{
private:
int i;
public:
bar(int);
void f();
};
}
#endif

//foo.cpp
n::bar::bar(int n) : i(n)
{
}

void n::bar::f()
{
//whatever
}

HTH,
S. Armondi

Jul 19 '05 #3

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

Similar topics

11
by: Georg Teichtmeister | last post by:
Hello! We are developing a math - library for realtime applications and want to use some given mathlibraries as base(ipp, MTL, .. ). Our library is a wrapper for those and you should be able to...
5
by: Charles L | last post by:
Can someone explain to me what the following means? "C permits multiple definitions of a variable in any given namespace, provided the definitions are the same and it generates only a single...
9
by: lbj137 | last post by:
I have two files: A.c and B.c. In both files I define a global variable, int xxxx; When I compile with a green hills compiler (and also i think with a GNU compiler) I get no errors or warnings....
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
11
by: lars.uffmann | last post by:
Easily described problem: Using g++ version 3.3.5 under suse 9.3, bla.h: ----------- #ifndef myTEST #define myTEST ZFSInt test; #endif
3
by: Student | last post by:
Hi all, While compiling a program I had this message : tools.o(.data+0x0): multiple definition of `VAR_1' main.o(.data+0x0): first defined here tools.o(.data+0x4): multiple definition of...
3
by: Jens Müller | last post by:
I have a file here with several enums: #ifndef PLANARSEP_OPTIMIZE_H #define PLANARSEP_OPTIMIZE_H enum fund_cycle_behavior_t {PASS_MODE_FIRST, PASS_MODE_BEST, PASS_MODE_ALL};
10
by: zfareed | last post by:
Similar problem to the previous post. I have created a project with about 7 files including 3 header files and 3 implementation files. I am getting a multiple definition error when compiling for...
6
by: Gaijinco | last post by:
I'm having a weird error compiling a multiple file project: I have three files: tortuga.h where I have declared 5 global variables and prototypes for some functions. tortuga.cpp where I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.