VC++ 6.0 Debugger Help

This is a discussion on VC++ 6.0 Debugger Help within the C++ Programming forums, part of the General Programming Boards category; When I move variables to quickwatch, a lot of the times I get this, "Error: Variable could not be found" ...

  1. #1
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    VC++ 6.0 Debugger Help

    When I move variables to quickwatch, a lot of the times I get this, "Error: Variable could not be found" error.. this seems to be the case with class and local function variables... it seems the only time I can watch variables is when they are declared in main( )... is this normal? is anyone else experiencing this problem..?? is it possible to watch private class member variables? if so, how...??!
    Attached Images Attached Images  
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    I've never really noticed a problem. But... are your objects in scope at the time you are noticing this problem? A variable that goes out of scope will have some error message associated with it in the watch window; like if you step into a function where some object or variable doesn't exist anymore, the watch for that object will change from some value into the error message. Later it might change back to a value once you've stepped out of the function and are back in the calling function where the object/variable was definied. That is probably the only thing I can think of at the moment.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Hi,

    First, I would suggest you avoid using the Quick Watch and it's associated dialog box, which is a "modal" dialog box and won't let you do anything else until you close it. I think this is easier: highlight the variable you want to watch, and then drag it down into the Watch pane and release it.

    Here is a sample program:
    Code:
    #include <iostream>
    #include <string> 
    
    using namespace std;
    
    class Apple
    {
    private:
    	int num;
    	double size;
    
    public:
    	Apple(int n=0, double s=0)
    	{
    		num = n;
    		size = s;
    	}
    	void display()
    	{
    		cout<<num<<endl<<size<<endl;
    	}
    };
    
    int main()
    {
    	int a;
    	int b = 10;
    	float c;
    
    	Apple myApple(1, 3.2);
    	myApple.display();
    	
    	
    	return 0;
    }
    The following is what the debugger looks like when I use Step Into to start the debugging, and after I drag three variables in main() down to the Watch pane--the cursor is on the opening parenthesis of main():
    Attached Images Attached Images  
    Last edited by 7stud; 04-19-2005 at 09:00 PM.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Now, if I drag the variable myApple into the Watch Pane, I get this:
    Attached Images Attached Images  

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Ok, that doesn't look too promising, but notice the cursor is still on the first parenthesis of main(), so execution hasn't even started yet. If I click on Step Into once, the debugger looks like this:
    Attached Images Attached Images  

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    The left pane is the Variables window, and the right pane is the Watch window. Notice that '+' sign in front of myApple, if I click the '+' sign, it will expand myApple. I can expand it in both the Variables window and the Watch window:
    Attached Images Attached Images  

  7. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    At that point, all the variables contain junk values. If I click on Step Into one more time, b shows a value of 10. If I click Step Into one more time after that, the debugger jumps up into the Apple constructor, and then steps through the process of constructing the myApple object. After stepping through the constructor, this is what the debugger shows:
    Attached Images Attached Images  

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    num and size are private class member variables, and they are displayed in the Watch window, so hopefully that helps.

    You should also try hovering your cursor over the variables in the code window--a tool tip will pop up, showing you the value of the variable. However, for myApple it only shows:
    Code:
    myApple={...}
    it seems the only time I can watch variables is when they are declared in main( )
    You can only see variables that are in scope. For instance, when I use Step Into to jump up into the constructor for the Apple class, all the variables in main display:

    error: symbol not found.

    The debugger steps into the role of the compiler, and it cannot see variables that are out of scope.
    Last edited by 7stud; 04-19-2005 at 10:20 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. makefile exported by vc 6.0 doesn't work
    By wow in forum Windows Programming
    Replies: 7
    Last Post: 03-24-2006, 03:20 PM
  2. Can't compile this with VC 6.0
    By uriel2013 in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 07:43 PM
  3. VC++ 6.0 debugger
    By flynn in forum Windows Programming
    Replies: 2
    Last Post: 01-08-2003, 10:42 PM
  4. adding a header file in VC 6.0
    By stimpyzu in forum C++ Programming
    Replies: 5
    Last Post: 10-28-2002, 01:26 AM
  5. VC 6.0 compiled error
    By alan4100 in forum Windows Programming
    Replies: 4
    Last Post: 09-17-2001, 03:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21