如何告诉皮棉跟踪指向矢量的保管指针? [英] How can I tell lint to track a custodial pointer to a vector?

查看:79
本文介绍了如何告诉皮棉跟踪指向矢量的保管指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以循环执行并通知一些指针,并将其存储在向量中:

I have some code that loops and news up some pointers and stores them in a vector:

std::vector<InputBox*> m_octets; 
...  
InputBox* octet = new InputBox(rect, title, touch_num);
m_octets.push_back(octet);

在类析构函数中,我在m_octets上使用for_each并为每个指针调用析构函数.我认为这一切都很好.全部编译,单元测试通过.问题在于Gimpel的PC绒毛不喜欢它.它看到八位位组"是一个尚未释放的托管指针(警告429).我当然可以禁用该警告,但是手册(11.2.1)指出了这种含义.我原以为会工作:

In the class destructor I for_each over m_octets and invoke the destructor for each pointer. I think this is all good. It all compiles and the unit tests pass. The problem is Gimpel's PC-lint doesn't like it. It sees that `octet' is a custodial pointer that has not been freed (Warning 429). I can of course disable that warning but the manual (11.2.1) indicates there is a semantic for this. I would have thought would work:

-sem(*push_back, custodial (1))

不幸的是,它没有任何作用.我尝试了各种组合,包括完全指定m_octets.push_back,但似乎没有任何效果.有人知道给定示例的命令的正确形式吗?

Unfortunately it has no effect. I've tried various combinations including fully specifying m_octets.push_back but nothing seems to work. Does anybody know the proper form of this command for the example given?

推荐答案

这个对我来说很好:-sem(std::vector::push_back, custodial(1))

这篇关于如何告诉皮棉跟踪指向矢量的保管指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆