警告 C26460
函数“function”的引用参数“argument”可以标记为
const
(con.3)。
备注
按引用传递对象指示函数可能会修改对象。 如果这不是函数的意图,最好将参数标记为常量引用。
代码分析名称: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
}