Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7069189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:24:55+00:00 2026-05-28T05:24:55+00:00

anisha@linux-dopx:~/> gdb a.out (gdb) watch dummyA::x Cannot reference non-static field x (gdb) x is

  • 0
anisha@linux-dopx:~/> gdb a.out
(gdb) watch dummyA::x
Cannot reference non-static field "x"
(gdb) 

x is a private member of a class named dummyA.
How to set a watch point on the private member of the class?

Language: C++
Platform: Linux

EDIT 1:

#include <iostream>
using namespace std;

class dummyA
{
    int x;

    public:
        dummyA ()
        {
            x = 0;
        }

        void test ()
        {
            x++;
        }
};

int main ()
{
    dummyA obj;
    obj.test ();
    obj.test ();
    obj.test ();
}

Output:

(gdb) watch obj.x
No symbol "obj" in current context.

(gdb) watch obj::x
No symbol "obj" in current context.

Now, what does that error mean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:24:56+00:00Added an answer on May 28, 2026 at 5:24 am

    Suppose you have this:

    class A {
     private:
       int x;
    }
    
    int main()
    {
        A foo;
        A bar;
        return 0;
    }
    

    Now you have two instances of A named foo and bar. If you tell the debugger to watch A::x how does it know which instance you mean?

    When you watch an instance variable (of which there is one for each instance) instead of a static variable (of which there is only one for every class) you need to specify which instance’s variable you want to watch. You are specifying which class’ variable you want to watch. And while that would be OK with a static variable (there is only one static variable per class) it’s not OK with an instance variable.

    In this case, in main, after stepping past the two lines A foo; and A bar; you could do:

    watch foo.x
    

    or

    watch bar.x
    

    and it would work just fine. You have to step past those lines because not even the names (much less the objects they refer to) exist until after them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

anisha@linux-dopx:~/Desktop/notes/pomodoro> ls timer.cpp anisha@linux-dopx:~/Desktop/notes/pomodoro> qmake -project anisha@linux-dopx:~/Desktop/notes/pomodoro> qmake anisha@linux-dopx:~/Desktop/notes/pomodoro> make g++ -c -m64 -pipe
class A { private def sayHello() { println Anish } } def a_obj =
From http://www.parashift.com/c++-faq-lite/basics-of-inheritance.html#faq-19.5 A member (either data member or member function) declared in a protected
This might be a stupid question. Dependency properties are static in nature. Button (which
When I try to run .aspx page with next code: System.IO.File.Delete(~/img/afisha/ + fileName); it
if i define a groovy variable def x = anish$ it will throw me
When comparing two strings how to avoid checking if a string is of different
I have table named Schedule which has fields named TeacherName and ClassTakenDate.The values in
All groovy special character #{\'}${}/', needs to be replaced by \ in front in
How can I build a regex example that can escape single quote and backslash

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.