Click here to Skip to main content
15,890,438 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CString to CLongBinary Pin
Giles21-Aug-01 4:42
Giles21-Aug-01 4:42 
GeneralRe: CString to CLongBinary Pin
Uwe Keim21-Aug-01 4:51
sitebuilderUwe Keim21-Aug-01 4:51 
Generalwhats wrong here??about waveinreset!! Pin
hapcoer20-Aug-01 23:43
hapcoer20-Aug-01 23:43 
Generala simple question about global variable Pin
Gérald Mercet20-Aug-01 23:04
Gérald Mercet20-Aug-01 23:04 
GeneralRe: a simple question about global variable Pin
Christian Graus20-Aug-01 23:29
protectorChristian Graus20-Aug-01 23:29 
GeneralRe: a simple question about global variable Pin
Gérald Mercet20-Aug-01 23:43
Gérald Mercet20-Aug-01 23:43 
GeneralRe: a simple question about global variable Pin
Christian Graus20-Aug-01 23:53
protectorChristian Graus20-Aug-01 23:53 
GeneralRe: a simple question about global variable Pin
Malcolm McMahon21-Aug-01 0:36
Malcolm McMahon21-Aug-01 0:36 
For global variables you need two kinds of declaration. You need to actually define them in exactly one .cpp file. This creates the space they occupy and initialises them.

The other declaration gives code outside of the module in which they are defined access to them.

So in the .h file you should put, say,
<br />
extern MyType *myGlobalPointer;<br />

in _one_ of the .cpp files you put
<br />
MyType *myGlobalPointer = NULL;<br />


extern is actually ignored these days but I prefer to put it in anyway for clarity.

Global Variables are pretty unpopular these days. Usually the substitute is to use static members of classes. So, for example, if you are declaring a "singleton" class, that is a class of which you will create only one instance you might do

<br />
class MyConnection : public CConnection {<br />
...<br />
public:<br />
  static MyConnection *theConnection;  // declare a static pointer<br />
<br />
..<br />
 <br />
  MyConnection( ... ) : CConnection (... ) {<br />
  ...<br />
  theConnection = this;  // set pointer to sole instance<br />
  }<br />

And in cpp
<br />
<br />
MyConnection *MyConnection::theConnection = NULL; <br />
//          allocate the pointer<br />
<br />
...<br />
<br />
// access the connection<br />
<br />
MyConnection::theConnection->disconnect();<br />
<br />

Generalcrypt Pin
20-Aug-01 22:37
suss20-Aug-01 22:37 
GeneralRe: crypt Pin
Tim Deveaux21-Aug-01 6:15
Tim Deveaux21-Aug-01 6:15 
GeneralSerialization Pin
Nick Armstrong20-Aug-01 22:09
Nick Armstrong20-Aug-01 22:09 
GeneralRe: Serialization Pin
Niklas L20-Aug-01 22:32
Niklas L20-Aug-01 22:32 
GeneralHELP !!! CHARFORMAT2 and yHeight Pin
20-Aug-01 21:42
suss20-Aug-01 21:42 
GeneralMDI application Pin
The_Server20-Aug-01 21:14
The_Server20-Aug-01 21:14 
GeneralRe: MDI application Pin
Ulf Öhlén20-Aug-01 22:36
Ulf Öhlén20-Aug-01 22:36 
GeneralCompress Pin
20-Aug-01 20:21
suss20-Aug-01 20:21 
GeneralRe: Compress Pin
Christian Graus21-Aug-01 0:51
protectorChristian Graus21-Aug-01 0:51 
GeneralCOleDateTimeSpan wierdness.... Pin
Liam O'Hagan20-Aug-01 20:13
Liam O'Hagan20-Aug-01 20:13 
GeneralRe: COleDateTimeSpan wierdness.... Pin
Kelly Herald21-Aug-01 17:13
Kelly Herald21-Aug-01 17:13 
GeneralRe: COleDateTimeSpan wierdness.... Pin
Liam O'Hagan21-Aug-01 20:54
Liam O'Hagan21-Aug-01 20:54 
GeneralSome body Help me !!! Pin
quangpm09a20-Aug-01 15:16
quangpm09a20-Aug-01 15:16 
GeneralRe: Some body Help me !!! Pin
Sam C20-Aug-01 15:46
Sam C20-Aug-01 15:46 
QuestionIt's friggin HUGE! Is VC++ on crack? Pin
Todd Smith20-Aug-01 14:04
Todd Smith20-Aug-01 14:04 
AnswerRe: It's friggin HUGE! Is VC++ on crack? Pin
CodeGuy21-Aug-01 2:09
CodeGuy21-Aug-01 2:09 
QuestionOnly got a .dll file; Now what?? Pin
20-Aug-01 12:55
suss20-Aug-01 12:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.