【发布时间】:2015-12-18 22:50:23
【问题描述】:
我需要在 for 循环的每个语句中打印一些内容。因为我的程序在 for 循环中崩溃了。所以我尝试在for循环中添加trace语句,
for ( ICollection::const_iterator iter = pCol->begin(NULL),OutputDebugString(L"One"); iter != pCol->end(NULL); ++iter)
{ //see OutputDebugString
我收到以下错误,
错误 1 错误 C2664: 'IIteratable::ConstIterator::ConstIterator(std::auto_ptr<_ty>)' : 无法将参数 1 从 'const wchar_t [4]' 转换为 'std::auto_ptr<_ty>' 文件名.cpp 629
现在我在示例应用程序中尝试了同样的事情,它工作正常,
void justPrint(std::string s)
{
cout<<"Just print";
}
int main()
{
int i;
for(i = 0,justPrint("a"); i<3; i++)
{
}
return 0;
}
OutputDebugString 和 justPrint 都返回 void,我在代码中做错了什么。
【问题讨论】:
-
pCol的类型是什么?还有为什么在begin()和end()中使用NULL? -
std::auto_ptr...一些遗留代码需要升级... -
pCol 是某种内部类型的智能指针,
TNSmartPtr<IEbCollection> pCol并传递了 NULL,因为它需要一些会话对象。都与内部管理有关。是否应该出现任何错误?因为没有跟踪语句一切都很好。 -
@BryanChen 是的。但它巨大的旧遗留代码。我正在修复小模块上的错误。如果尝试这样做,需要大量重构。
-
在 for 循环的第一个参数中包含 print 语句有什么意义?由于无论如何它只会执行一次,为了清楚起见,您不妨将其移出循环。
标签: c++ loops for-loop trace comma-operator