1

I'd like to know if there is a way to inspect the data os this piece of code with a breakpoint in Visual Studio:

someClass.someVar = 12;

In the same way i would with this one:

someClass.SetSomeVar(12);

There is a way to know the variable's data without making getters and setters ???

khofez
  • 65
  • 1
  • 8
  • 1
    Define "inspect". If it's a primitive, there isn't anything to inspect really, except the data before and after in the watch window. If the type overloads `operator=` you can just place a breakpoint in there. – StoryTeller - Unslander Monica Dec 29 '16 at 12:05
  • when i said "inspect", i meant when you set a breakpoint on a Set method and on the call stack you can see every line of code that is calling it – khofez Dec 29 '16 at 12:18
  • 1
    I see. For overloaded `operator=` you place a regular breakpoint. For primitives, see **ilim**s answer. – StoryTeller - Unslander Monica Dec 29 '16 at 12:19
  • @StoryTeller If the class has any attributes that can be modified without using operator=, then overloading that single operator may be insufficient. I'd suggest setting data breakpoints for each attribute of the class/type. It's more tedious, but at least you don't modify the source code. – ilim Dec 29 '16 at 12:42
  • 1
    @ilim - The class in question which my overload `operator=` is `decltype(someVar)`, not `someClass` – StoryTeller - Unslander Monica Dec 29 '16 at 12:43

1 Answers1

5

There is a concept called data breakpoint that may help you achieve debugging as you stated, without necessarily modifying your code. You may also want to look into this post on data breakpoints.

However if the type T that someVar belongs to is not primitive, the simplest way to achieve the desired result is overloading operator= of that type, and set a simple breakpoint in the scope of that overloaded method.

Community
  • 1
  • 1
ilim
  • 4,477
  • 7
  • 27
  • 46