[英]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 :- 要在鼠标悬停在其上
.natvis
用E2<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<*>">
<SmartPointer Usage="Minimal">atDerive</SmartPointer>
</Type>
Result 结果
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<*>">
<SmartPointer Usage="Minimal">atBase</SmartPointer>
</Type>
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<*>">
<SmartPointer Usage="Minimal">($T1*)atBase</SmartPointer>
<DisplayString>{($T1*)atBase}</DisplayString>
</Type>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.