Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

global variable causes strange problem 1

Status
Not open for further replies.

HyperEngineer

Programmer
May 8, 2002
190
US
I don't know why this happens.

If I have a global variable, called out in the .h file above the class definition, and I use it in an if statement it causes a strange thing to happen.

If I have this code

Code:
CString* b;
int strLen;
if (variable1 < ENUM_1)
   return variable1;

strLen = b->GetLength();

I do not get the list of members when I type -> after the variable b.

However, if I have this

Code:
CString* b;
int strLen;
int variable2;
if (variable2 < ENUM_1)
   return variable2;

strLen = b->GetLength():

This will give me the list of members when I type -> after the b.

Also, if I do this, putting the global variable in parenthesis

Code:
CString b;
int strLen;

if ((variable1) < ENUM_1)
   return variable1;

strLen = b->GetLength();

This also works.

Any ideas?
 
probably a bug in intellisense. I wouldn't worry about it unless typing 9 chars on your own really is that stressful!:)
 
Wow, you should do QA work for Microsoft's Visual Studio team! :)
I've had a ton of strange problems like that, but I've never had the time or patience to try to figure out exactly what causes it...
 
Try deleting the .ncb file and let VS rebuild it for you. It probably got screwed at some point and can't work out what it wants.

I can't see how your last example would work. Shouldn't it be
Code:
CString b;
int strLen;

if ((variable1) < ENUM_1)
   return variable1;

strLen = b.GetLength();

The first example should have a new somewhere
Code:
CString* b = new CString("very very nice");
int strLen;
if (variable1 < ENUM_1)
   return variable1;

strLen = b->GetLength();
 
I doubt it's a problem with the .ncb file. When the .ncb file gets corrupt you usually just start losing classes from your ClassView window.
 
I would regard this a feature rather than a bug.

Anything that discourages using global variables has my vote.

;-)



/Per
[sub]
www.perfnurt.se[/sub]
 

xwb,

I had to clean out all the old files that weren't .cpp or .h or .rc. Then I did a rebuild and things worked out fine. Didn't need the parenthesis any more. I also, obviously, kept the .dsw and .dsp files. Thanks.

Per,

The variable was actually a protected member of the base class. The funcion was public member function of the base class. I try not to use globals if I can avoid them. But this seemed more efficient and was taken from Mark Nelson's code. Thanks.

HyperEngineer
If it ain't broke, it probably needs improvement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top