boost lib中的语句,(void)p; 这是什么意思?

RLT*_*RLT 5 c++ templates boost

我在Boost Library中遇到了一段代码,用于offset_ptr.在boost/interprocess/offset_ptr.hpp下

typedef PointedType *                     pointer;
...
    //!Constructor from other pointer.
    //!Never throws.
    template <class T>
    offset_ptr(T *ptr) 
    {  pointer p (ptr);  (void)p; this->set_offset(p); }
Run Code Online (Sandbox Code Playgroud)

我想知道什么是声明(void)p; 呢?

Ski*_*izz 1

找出答案的一种方法是在该行代码上放置一个断点,然后单步执行以找出它的作用。您甚至可以重新格式化代码,以允许您在该特定语句上设置断点(没有法律禁止编辑这些文件 - 只是不要更改实际代码)。

然而,我的猜测是,该pointer类型正在使用某种形式的惰性求值,模拟的强制转换运算符会调用一个set_offset方法,因此可能this->set_offset(p)需要p设置一个有效的偏移量,并且执行该操作(void)p只会强制它发生。