开发者

constant parameters in a function [closed]

开发者 https://www.devze.com 2023-03-06 10:48 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can b开发者_StackOverflow中文版e reopened, visit the help center. Closed 11 years ago.
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消