在MS Visual Studio 2010监视窗口中评估模板函数
Evaluate Template Function in MS Visual Studio 2010 Watch Window
问题:有什么方法可以从MS Visual Studio Watch 2010窗口评估模板函数吗?
详细信息:我知道如果我有以下功能:
void Test (CString& sSample)
{
OutputDebugString (_T("The value of Sample is ") + sSample);
}
我可以在监视窗口中使用,并在调试时在输出窗口中打印输出。但是,我看到当使用下面这样的模板函数时,这是不起作用的:
template<class T>
void Test (T& t)
{
OutputDebugString (_T("The value when T is string is: ") + t);
}
我能以某种方式实现它吗?我知道autoexp.bat对变量很有帮助。但对它在函数中的行为一无所知。有什么帮助吗?
调试模板函数没有问题。这里的问题是OutputDebugString,它的参数是字符串,所以"Text1"+"Text2"不起作用,"Text1"+123不起作用。它恰好与CString一起工作,否则它就不是真正的模板材料。
这将适用于VS 2013(在C++=>语言选项中,启用RTTI),它可能不适用于VS 2010:
template<class T> void Test2(T& t)
{
OutputDebugStringA( "typeid(t).name=" );
OutputDebugStringA( typeid(t).name() );
OutputDebugStringA( "n" );
}
int i = 0;
CString str = "str";
Test(i);
Test(str);
无论如何,只要试着让模板函数更简单,这样它就可以处理整数、浮点等。或者让它区分数字和字符串。
相关文章:
- 在编译时评估函数开销的通用方法
- 函数参数计算顺序与 Lambda 捕获评估顺序
- 为什么不能订购函数参数评估
- 表达式未评估为常数两个级别的constexpr函数(编译器错误?)
- C2064:术语未评估为1个参数qtConcurrent :: map的函数
- 在评估不同参数的constexpr函数时,运行时差异
- 尝试创建一个评估字符的bool函数,如果字母数字为字母,则返回true
- 委托构造函数的评估
- std :: initializer_list:错误c2064:项未评估为0参数的函数
- 单步执行函数,但不进入VS2017的参数评估
- 用于评估导致Segfault的Postfix的函数
- 编译时间评估函数以计算常数
- 我如何评估宏函数的算术表达以传递到C预处理器中的另一个宏函数
- 如何在未评估的上下文中将成员函数的结果类型应用于类成员
- 评估采用函数参数的元功能,干燥,而无需使用宏
- 推迟对函数通话论证的评估
- 死亡测试时函数调用的评估错误
- 延迟评估模板类型函数
- Callgrind:如何使用Callgrind工具来评估函数速度
- 为什么我的数学表达式评估函数不能在Windows上工作