简体   繁体   English

使.natvis显示SmartPointer <T> 作为static_cast <T*> (无效*)

[英]make .natvis show SmartPointer<T> as static_cast<T*>(void*)

E2<T> is a smart pointer. E2<T>是智能指针。

To enable a tool-tip of E2<T>->aField when mouse hovers above it, I can create .natvis like :- 要在鼠标悬停在其上.natvisE2<T>->aField的工具提示,我可以创建.natvis例如:-

.cpp 的.cpp

class Blank{
    public: int sss=5;
};
template<class T> class E2 {
    public: T* operator->(){
        return static_cast<T*>(atDerive);
    }
    T* atDerive;          //#
};
int main(){
    Blank k2; k2.sss=32;
    E2<Blank> e2;
    e2.atDerive=&k2;
    e2->sss=4;
}

.natvis .natvis

  <Type Name="E2&lt;*&gt;">
    <SmartPointer Usage="Minimal">atDerive</SmartPointer>
  </Type>

Result 结果

在此处输入图片说明

Problem 问题

The above approach doesn't work if the content void* is in the base class E1 . 如果内容void*在基类E1中,则上述方法不起作用。

.cpp 的.cpp

class E1{
    public: void* atBase=nullptr;    //#
};
template<class T> class E2 : public E1{
    public: T* operator->(){
        return static_cast<T*>(atBase);
    }
};
int main(){
    Blank k; k.sss=31;
    E2<Blank> e2;
    e2.atBase=&k;
    e2->sss=4;
}

.natvis (not work - no tool-tip appear) .natvis (不起作用-没有工具提示出现)

  <Type Name="E2&lt;*&gt;">
    <SmartPointer Usage="Minimal">atBase</SmartPointer>
  </Type>

Question

How to modify .natvis to enable tool-tip to show void* that is in the base class ( E1 )? 如何修改.natvis以使工具提示显示基类( E1 )中的void*

Add a type cast from void* to template type T (you can get it as a $T1 in your .natvis file) 将从void*强制转换的类型添加到模板类型T (您可以在.natvis文件中将其作为$ T1获得)

<Type Name="E2&lt;*&gt;">
  <SmartPointer Usage="Minimal">($T1*)atBase</SmartPointer>
  <DisplayString>{($T1*)atBase}</DisplayString>
</Type>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么不能static_cast一个双void指针? - Why can't static_cast a double void pointer? 这里“int []”的目的是什么:“std::void_t <int[static_cast<int> (-1) &lt; static_cast<int> (0)]&gt;;" </int></int[static_cast<int> - What is the purpose of "int[]" here: "std::void_t<int[static_cast<Int>(-1) < static_cast<Int>(0)]>;" void * with static_cast vs intptr_t with reinterpret_cast - void* with static_cast vs intptr_t with reinterpret_cast 在VS 2010中,static_cast无法从void *转换为C ++中的size_t错误 - static_cast cannot convert from void* to size_t error in C++ in VS 2010 为什么我不能static_cast一个包含void *的元组到一个包含char *的元组? - Why can't I static_cast a tuple containing a void* to one containing a char*? 为什么我不能将 void* static_cast 转换为函数指针? - Why can't I static_cast a void* to a pointer-to-function? SFINAE:“ static_cast <void> ()”或“,void()”? - SFINAE: 'static_cast<void>()' or ', void()'? 为什么std :: forward返回static_cast <T&&> 而不是static_cast <T> ? - Why does std::forward return static_cast<T&&> and not static_cast<T>? 为什么 static_cast 不能将 ulong 转换为 uchar* - Why static_cast can't cast ulong to uchar* 使用* void作为static_cast的缓冲区 - using *void as a buffer for static_cast
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM