|
From: Luigi S. <gi...@li...> - 2002-02-04 22:29:29
|
Hi, Horst
Here is my opinion about your link error, as for the other two things, I
don't have a solution.
Your code is placed in two files: one is "arrh.h" and the other is "main.cpp".
the former, as stated by its extension, is an header file, as a rule of
thumb, these files should contain declarations only.
For instance:
class arrhenius { ... };
In your case, you have:
class arrhenius { ... } arh;
You not only declared the class "arrhenius", but also defined the variable
"arh".
Since the language expects to find one definition for each variable, if you
include the header in two different source files, the linker will find two
definition for the same variable and will issue an error message.
I suggest you change your code as follows:
arrh.h
------------
#ifndef arrh_H
#define arrh_H
class arrhenius
{
...
};
#endif // not defined arrh_H
main.cpp
-------------
#include "arrh.h"
int
main()
{
...
arrhenius arh;
...
}
At 08:12 04/02/02 +0000, Horst Roessner wrote:
>Hello and moin moin,
>
>I have a seriously problem. The following code produced a linker error and
>no code is build.
>c:\dev\dev-c++\testproj\arrh.o(.bss+0x0)://c/dev/dev-c++/testproj/arrh.cpp:
>multiple definition of `arh'
>c:\dev\dev-c++\testproj\main.o(.bss+0x0)://c/dev/dev-c++/testproj/main.cpp:
>first defined here
>If i commented out the include, all is compiled fine. I does not
>understand it. Can anyone help me ? Thanks in advance.
>File:arrh.h
>#ifndef arrh_H
>#define arrh_H
>[...]
>class arrhenius
>{
>public:
>arrhenius();
>[...]
>bool calc();
>} arh;
>
>File: main.cpp
>#include <cstdlib>
>#ifndef arrh_H
>#include "arrh.h"
>#endif
>int main(int argc, char *argv[])
>{
>[...]
>bool b = arh.calc();
>[...]}
>#endif
>There are two other questions.
>Last day I have integrated a win api referenz as winhelp into dev-c++.
>After copy it in the help directory, it was automaticly integrated. Great !!
>Now I seek such for C/C++ commands, a language reference. Any tip ?
>Where can I find a list of changes between gcc 2.9.5.2 and gcc 2.9.5.3 ?
>I could not find anything.
>greetings
>Horst
>
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
--
Luigi
gi...@li...
|