警告 C26461

函数“function”的指针参数“argument”可标记为指向 const 的指针 (con.3)。

备注

具有 T* 参数的函数有可能修改对象的值。 如果这不是该函数的意图,最好将指针改为 const T*

代码分析名称:USE_CONST_POINTER_ARGUMENTS

示例

struct MyStruct
{
    void MemberFn1() const;
    void MemberFn2();
};

void Function1_Helper(const MyStruct* myStruct);
void Function1(MyStruct* myStruct) // C26461, neither of the operations on myStruct would modify the pointer's value.
{
    if (!myStruct)
        return;

    myStruct->MemberFn1();      // The member function is const
    Function1_Helper(myStruct); // Function1_Helper takes a const
}

void Function2(MyStruct* myStruct)
{
    if (!myStruct)
        return;

    myStruct->MemberFn2(); // The member function is non-const, so no C26461 will be issued
}

另请参阅

C++ Core Guidelines con.3