| delorie.com/archives/browse.cgi | search |
| From: | DavMac AT iname DOT com (Davin McCall) |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: and another thing... |
| Date: | Thu, 27 May 1999 04:23:54 GMT |
| Organization: | Monash Uni |
| Lines: | 61 |
| Distribution: | world |
| Message-ID: | <374cc852.7240794@newsserver.cc.monash.edu.au> |
| References: | <Pine DOT SUN DOT 3 DOT 96 DOT 990526115225 DOT 18233A-100000 AT silver DOT cs DOT umanitoba DOT ca> |
| NNTP-Posting-Host: | damcc5.halls.monash.edu.au |
| X-Trace: | towncrier.cc.monash.edu.au 927779003 22630 130.194.198.138 (27 May 1999 04:23:23 GMT) |
| X-Complaints-To: | abuse AT monash DOT edu DOT au |
| NNTP-Posting-Date: | 27 May 1999 04:23:23 GMT |
| X-Newsreader: | Forte Free Agent 1.1/32.230 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
On Wed, 26 May 1999 11:56:59 -0500, Mark Phillips
<umphill5 AT cs DOT umanitoba DOT ca> wrote:
>
[some snipped]
>Creating: test.exe
>Error: main.o(.data+0x0):main.cc: multiple definition of 'foo'
>Error: h.o(.data+0x0):h.cc first defined here
>
>When I do this:
[at end of response]
>Shouldn't the preprocessor directives in 'header.h' handle the multiple
>declaration linking errors?
You need to use the 'extern' keyword for the variable ie.
extern bool foo;
>love
>mark
I'm honored. ;-)
regards,
Davin.
>
>// file #1 main.cc
>#include "header.h"
>
>int main()
>{
> fun1();
> return 0;
>}
>
>// file #2 h.cc
>#include "header.h"
>
>void fun1()
>{
> foo = 1;
>}
>
>// file #3 header.h
>#ifndef HEADER_H
>#define HEADER_H
>
>void fun1();
>bool foo;
>
>#endif
>
>
__________________________________________________________
*** davmac - sharkin'!! davmac AT iname DOT com ***
my programming page: http://yoyo.cc.monash.edu.au/~davmac/
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |