|
-
December 8th, 2002, 08:21 AM
#1
How to define a global variable in .h file?
I am trying to keep all global variables in one .h file.here is a example like this:
// stdafx.h
#if !defined(AFX_STDAFX)
#define AFX_STDAFX
#include <stdio.h>
char word[20];
#endif
//main.cpp
#include "stdafx.h"
int main(int argc, char* argv[])
{
strcpy(word,"ok ,you r welcome",20);
printf(word);
return 0;
}
but the result like this:
Linking...
StdAfx.obj : error LNK2005: "char * word" (?word@@3PADA) already defined in console.obj
Debug/console.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
what should i do, if i intend to keep all global variables in a header file.
-
December 8th, 2002, 09:07 AM
#2
Please see other posts on globals and headers, there is good information already on the board. Specifically:
"how to have varibles globle to a file". [spellingsmatch actual subject line]
-
December 8th, 2002, 12:01 PM
#3
in addition to TheCPUWizard's post - the links to these threads are:
1: how to have varibles globle to a file?
2: how to have varibles globle to a file?
(it's easier to click, than to search )
Mikey
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|