Re: How to Define a global const class variable in MFC?
- From: "Tom Serface" <tom.nospam@xxxxxxxxxxxxx>
- Date: Sun, 31 Aug 2008 08:28:39 -0700
Just an opinion...
I would not make this a global variable. Instead I would probably add it to the main app class or perhaps, a class that contains other variables like this that is, itself, hosted in the main app class. That way you could access it with code like:
theApp.m_InfoArray.Add()
Which lets you know where it is hosted and also you could easily clean it up when exiting the application instance. This is also very easy to debug.
I try very hard not to use global variables these days and I've found it makes debugging and cleaning up much easier.
Tom
"Electronic75" <Electronic75@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:420537CC-30E0-4A6A-B24B-A54AC08B8AC2@xxxxxxxxxxxxxxxx
Hello :), I'm trying to define a global const class varibles in a MFC
application. This class holds an array of variables that I like to assign at
the beginning and I will use this variable and its stored const values in my
program in different classes. Now what I'm doing is to add a blank cpp file
to my project and then I define this class variable there.
#include "MyInfoArrayClass.h"
const CMyInfoArrayClass g_Info;
g_Info.Add(data1);
g_Info.Add(data2);
...
but compiler dose not see the definition and intellisense shows the type of
g_Info as int and returns SYNTAX error and redefinition of basic type. Even
when I place class definition in a header file and include header file in the
source file compiler returns same errors.
I have done this with a char type or int type, I mean I have defined a
global char or int variable, and I had no problem but when I want to define a
class type variable I encounter trouble.
Where I made a mistake?
thanks :)
.
- Follow-Ups:
- Re: How to Define a global const class variable in MFC?
- From: Electronic75
- Re: How to Define a global const class variable in MFC?
- Prev by Date: Re: Capturing USB data?
- Next by Date: Re: newbie question: Can I modify MFC source code?
- Previous by thread: Re: How to Define a global const class variable in MFC?
- Next by thread: Re: How to Define a global const class variable in MFC?
- Index(es):
Relevant Pages
|