共用方式為


警告 C26460

函式 'function ' 的參考引數 ' argument ' 可以標示為 const (con.3)。

備註

以傳址方式傳遞物件表示函式有可能修改物件。 如果這不是函式的意圖,最好將引數標示為 const 參考。

程式碼分析名稱: USE_CONST_REFERENCE_ARGUMENTS

範例

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

void Function1_Helper(const MyStruct&);
void Function1(MyStruct& myStruct) // C26460, see comments below.
{
    myStruct.MemberFn1();       // The member function is marked as const
    Function1_Helper(myStruct); // Function1_Helper takes a const reference
}

void Function2(MyStruct& myStruct)
{
    myStruct.MemberFn2(); // MemberFn2 is non-const and has the potential to modify data
}

另請參閱

C++ 核心指導方針 con.3