开发者

constant parameters in a function [closed]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜