constant parameters in a function [closed]
class foo
{
public:
void set(const int a)
{b=a;}
private:
int b;
};
Here a
is a constant parameter which is assigned to a non const
Applying the const modifier to a parameter indicates that the parameter may not be changed by the function. It does not mean, though, that if the parameter's value is assigned to another variable then that variable can't be changed.
The purpose is to assure callers that data they pass to the method will not be changed.
精彩评论