简体   繁体   中英

How to add custom visualization for pointer types in VS2015?

I am trying to write a custom visualizer for pointers of a C++ class, say Element, by creating a .natvis file in VS2015.

class Element
{
   int id;
   ......
};

int main()
{
   Element* pElem = GetElement();  // Visualise this pointer!

}

I want the debugger to show me value of the member id of the element when I hover my mouse over the pointer variable. How can I do this? So far I have tried the following, but it does not seem to be working.

<?xml version="1.0" encoding="utf-8"?>

<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
  <!-- VC 2015 -->

  <Type Name="Element*">
    <DisplayString>{ id={*this.id} }</DisplayString>
  </Type>

</AutoVisualizer>

You do not need to add the * . And there is no need for *this. when accessing a member of the current context (also see the comments regarding precedence of operators).

<Type Name="Element">
  <DisplayString>{ id={id} }</DisplayString>
</Type>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM