{"rsdb":{"rid":"158448","subhead":"","postdate":"0","aid":"118817","fid":"49","uid":"1","topic":"1","content":"
\n

\u5728C++<\/a>\u7684\u7c7b\u5b9a\u4e49\u91cc\u9762\uff0c\u53ef\u4ee5\u770b\u5230\u7c7b\u4f3c\u4e0b\u9762\u7684\u5b9a\u4e49\uff1a<\/p> \n

01classList {<\/p> \n

02private:<\/p> \n

03Node * p_head;<\/p> \n

04intlength;<\/p> \n

05\u2026\u2026<\/p> \n

06Public:<\/p> \n

07intGetLength ()const;<\/p> \n

08boolGetNodeInfo(constintindex,Node & buffer)const{\u2026\u2026 }<\/p> \n

09boolDeleteNode(constintindex);<\/p> \n

10\u2026\u2026\u2026\u2026<\/p> \n

11}<\/p> \n

\u53ef\u4ee5\u770b\u5230\uff0c\u5728GetLength\u548cGetNodeInfo\u4e24\u4e2a\u6210\u5458\u51fd\u6570\u7684\u53c2\u6570\u5217\u8868\u540e\u9762\u51fa\u73b0\u4e86\u4e00\u4e2aconst\u3002\u8fd9\u4e2aconst\u6307\u660e\u4e86\u8fd9\u4e2a\u51fd\u6570\u4e0d\u4f1a\u4fee\u6539\u8be5\u7c7b\u7684\u4efb\u4f55\u6210\u5458\u6570\u636e\u7684\u503c\uff0c\u79f0\u4e3a\u5e38\u91cf\u6210\u5458\u51fd\u6570\u3002<\/p> \n

\u5bf9\u4e8econst\u51fd\u6570\u7684\u5916\u90e8\u5b9a\u4e49\uff0c\u4e5f\u4e0d\u80fd\u5fd8\u8bb0\u4e66\u5199const\u9650\u5b9a\u7b26\uff0c\u5982\u4e0b\u9762\u7ed9\u51faGetLength\u51fd\u6570(\u6307\u8fd4\u56de\u94fe\u8868\u7684\u957f\u5ea6)\u7684\u5b9a\u4e49\uff1a<\/p> \n

1intList::GetLength()const\/\/\u8fd9\u91cc\u4f9d\u7136\u4e0d\u80fd\u5fd8\u8bb0const<\/p> \n

2{<\/p> \n

3Return length;<\/p> \n

4}<\/p> \n

\u5982\u679c\u5728const\u6210\u5458\u51fd\u6570\u7684\u5b9a\u4e49\u4e2d\u51fa\u73b0\u4e86\u4efb\u4f55\u4fee\u6539\u5bf9\u8c61\u6210\u5458\u6570\u636e\u7684\u73b0\u8c61\uff0c\u90fd\u4f1a\u5728\u7f16\u8bd1\u65f6\u88ab\u68c0\u67e5\u51fa\u6765\uff0c\u5982\uff1a<\/p> \n

1intList::GetLength()const<\/p> \n

2{<\/p> \n

3Return length++;\/\/\u9519\u8bef!<\/p> \n

4}<\/p> \n

const\u6210\u5458\u51fd\u6570\u5b58\u5728\u7684\u610f\u4e49\u5728\u4e8e\u5b83\u80fd\u88abconst\u5e38\u5bf9\u8c61\u8c03\u7528\u3002\u6211\u4eec\u90fd\u77e5\u9053\uff0c\u5728\u5b9a\u4e49\u4e00\u4e2a\u5bf9\u8c61\u6216\u8005\u4e00\u4e2a\u53d8\u91cf\u65f6\uff0c\u5982\u679c\u5728\u7c7b\u578b\u524d\u52a0\u4e00\u4e2aconst\uff0c\u5982const int x;\uff0c\u5219\u8868\u793a\u5b9a\u4e49\u7684\u91cf\u4e3a\u4e00\u4e2a\u5e38\u91cf\uff0c\u5b83\u7684\u503c\u4e0d\u80fd\u88ab\u4fee\u6539\u3002\u4f46\u662f\u521b\u5efa\u7684\u5bf9\u8c61\u5374\u53ef\u4ee5\u8c03\u7528\u6210\u5458\u51fd\u6570\uff0c\u8c03\u7528\u7684\u6210\u5458\u51fd\u6570\u5f88\u6709\u53ef\u80fd\u6539\u53d8\u5bf9\u8c61\u7684\u503c\uff0c\u6bd4\u5982\u4e0b\u9762\u8fd9\u6bb5\u7a0b\u5e8f\uff1a<\/p> \n

1constList myList;<\/p> \n

2myList.DeleteNode(3);\/\/\u9519\u8bef\uff0cDeleteLength\u662f\u975econst\u6210\u5458\u51fd\u6570<\/p> \n

\u663e\u7136\u8c03\u7528DeleteNode\u8fd9\u4e2a\u6210\u5458\u51fd\u6570\u5220\u9664\u4e00\u4e2a\u94fe\u8868\u7ed3\u70b9\u540e\uff0c\u5f88\u6709\u53ef\u80fd\u6539\u53d8\u5bf9\u8c61\u4e2dlength(\u94fe\u8868\u957f\u5ea6)\u8fd9\u4e2a\u503c\uff0c\u8fd9\u4e0d\u7b26\u5408const\u5bf9\u8c61\u7684\u89c4\u5b9a\u3002\u4f46\u662f\uff0c\u5982\u679c\u4e0d\u5141\u8bb8const\u5bf9\u8c61\u8c03\u7528\u4efb\u4f55\u6210\u5458\u51fd\u6570\u53c8\u662f\u975e\u5e38\u4e0d\u5408\u7406\u7684\u3002\u4e8e\u662f\uff0c\u6211\u4eec\u628a\u90a3\u4e9b\u80af\u5b9a\u4e0d\u4f1a\u4fee\u6539\u5bf9\u8c61\u7684\u5404\u4e2a\u5c5e\u6027\u503c\u7684\u6210\u5458\u51fd\u6570\u52a0\u4e0aconst\u8bf4\u660e\u7b26\uff0c\u8fd9\u6837\uff0c\u5728\u7f16\u8bd1\u65f6\uff0c\u7f16\u8bd1\u5668\u5c06\u5bf9\u8fd9\u4e9bconst\u6210\u5458\u51fd\u6570\u8fdb\u884c\u68c0\u67e5\uff0c\u5982\u679c\u786e\u5b9e\u6ca1\u6709\u4fee\u6539\u5bf9\u8c61\u503c\u7684\u884c\u4e3a\uff0c\u5219\u68c0\u9a8c\u901a\u8fc7\u3002\u4ee5\u540e\uff0c\u5982\u679c\u4e00\u4e2aconst\u5e38\u5bf9\u8c61\u8c03\u7528\u8fd9\u4e9bconst\u6210\u5458\u51fd\u6570\u7684\u65f6\u5019\uff0c\u7f16\u8bd1\u5668\u5c06\u4f1a\u5141\u8bb8\u3002\u6bd4\u5982\uff1a<\/p> \n

1constList myList;<\/p> \n

2myList.GetLength();\/\/\u6b63\u786e\uff0cGetLength\u662fconst\u5e38\u51fd\u6570\uff0c\u5b83\u8fd4\u56de\u94fe\u8868\u957f\u5ea6\uff0c\u7684\u786e\u6ca1\u6709\u6539\u53d8<\/p> \n

3\/\/\u5c5e\u6027\u503c\u7684\u884c\u4e3a\uff0c\u88ab\u68c0\u9a8c\u901a\u8fc7<\/p> \n

\u4f60\u53ef\u80fd\u4f1a\u95ee\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u5728\u4e00\u4e2aconst\u5e38\u5bf9\u8c61\u8c03\u7528\u6210\u5458\u51fd\u6570\u7684\u65f6\u5019\u518d\u8fdb\u884c\u68c0\u67e5\u5462?\u5982\u679c\u88ab\u8c03\u7528\u7684\u51fd\u6570\u4f1a\u6539\u53d8\u5bf9\u8c61\u7684\u5c5e\u6027\u503c\uff0c\u5219\u7acb\u5373\u6253\u4f4f\u5c31\u662f\u4e86\u3002\u8fd9\u6837\u5c31\u4e0d\u7528\u9ebb\u70e6\u5730\u5728\u6210\u5458\u51fd\u6570\u540e\u9762\u52a0const\u9650\u5b9a\u7b26\u4e86\u3002\u7136\u800c\uff0c\u8fd9\u65e0\u7591\u4f1a\u5927\u5927\u589e\u52a0\u7f16\u8bd1\u65f6\u95f4\u3002\u8003\u8651\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\uff1a<\/p> \n

1constList MyList;<\/p> \n

2MyList.GetLength();<\/p> \n

3\u2026\u2026<\/p> \n

4MyList.GetLength();<\/p> \n

5\u2026\u2026<\/p> \n

\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cGetLength\u88ab\u8c03\u7528\u4e86\u4e24\u6b21\uff0c\u4f46\u662f\u7f16\u8bd1\u65f6\u5374\u4e5f\u8981\u68c0\u67e5\u4e24\u6b21\uff0c\u5018\u4f7f\u4e00\u4e2a\u6210\u5458\u51fd\u6570\u88ab\u8c03\u7528\u591a\u6b21\uff0c\u90a3\u4e48\u4ed6\u5c06\u5728\u6bcf\u6b21\u8c03\u7528\u7684\u65f6\u5019\u90fd\u4f1a\u88ab\u68c0\u67e5\u3002\u8fd9\u663e\u7136\u5927\u5927\u4e0d\u5229\u3002\u800c\u5982\u679c\u5728\u5b9a\u4e49\u7c7b\u7684\u65f6\u5019\u52a0\u4e0aconst\u9650\u5b9a\u7b26\u5bf9\u5e38\u51fd\u6570\u52a0\u4ee5\u6807\u8bb0\uff0c\u90a3\u4e48\u7f16\u8bd1\u5668\u53ea\u662f\u68c0\u67e5\u4e00\u6b21\u5c31\u597d\uff0c\u5728const\u5bf9\u8c61\u8c03\u7528\u6210\u5458\u51fd\u6570\u65f6\uff0cconst\u51fd\u6570\u5c06\u4f1a\u88ab\u76f4\u63a5\u653e\u884c\u3002\u6240\u4ee5\uff0cC++<\/a>\u91c7\u53d6\u4e86const\u9650\u5b9a\u7b26\u63cf\u8ff0\u5e38\u51fd\u6570\u65b9\u6848\u800c\u6448\u5f03\u4e86\u540e\u8005\u3002\u6240\u4ee5\uff0c\u5373\u4f7f\u4e00\u4e2a\u51fd\u6570\u6ca1\u6709\u4fee\u6539\u5bf9\u8c61\u503c\u7684\u884c\u4e3a\uff0c\u5982\u679c\u6ca1\u6709\u52a0\u4e0aconst\u9650\u5b9a\u7b26\u8bf4\u660e\u662f\u5e38\u51fd\u6570\uff0c\u90a3\u4e48const\u5bf9\u8c61\u4f9d\u7136\u4e0d\u80fd\u8c03\u7528\u5b83\u3002<\/p> \n

\u7136\u800c\uff0c\u6709\u4e9b\u65f6\u5019\uff0c\u6211\u4eec\u5374\u5fc5\u987b\u8981\u8ba9const\u51fd\u6570\u5177\u6709\u4fee\u6539\u67d0\u4e2a\u6210\u5458\u6570\u636e\u503c\u7684\u80fd\u529b\u3002\u6bd4\u5982\u4e00\u4e9b\u5185\u90e8\u7684\u72b6\u6001\u91cf\uff0c\u5bf9\u5916\u90e8\u7528\u6237\u65e0\u6240\u8c13\uff0c\u4f46\u662f\u5bf9\u6574\u4e2a\u5bf9\u8c61\u7684\u8fd0\u884c\u5374\u5927\u6709\u7528\u5904,\u5982\u652f\u6301\u7f13\u5b58\u7684\u6280\u672f\u3002\u9047\u5230\u8fd9\u79cd\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u4e00\u4e2a\u6210\u5458\u6570\u636e\u5b9a\u4e49\u4e3amutable(\u591a\u53d8\u7684)\uff0c\u5b83\u8868\u793a\u8fd9\u4e2a\u6210\u5458\u53d8\u91cf\u53ef\u4ee5\u88abconst\u6210\u5458\u51fd\u6570\u4fee\u6539\u5374\u4e0d\u8fdd\u6cd5\u3002\u6bd4\u5982\u4e0b\u9762\u5b9a\u4e49\u4e86\u4e00\u4e2ais_valid\u7c7b\u6210\u5458\uff1a<\/p> \n

01classList<\/p> \n

02{<\/p> \n

03private:<\/p> \n

04\u2026\u2026<\/p> \n

05mutableboolis_valid;<\/p> \n

06\u2026\u2026<\/p> \n

07public:<\/p> \n

08boolCheckList()const<\/p> \n

09{<\/p> \n

10if(length >= 1) thenreturnis_valid =true;<\/p> \n

11elsereturnis_valid =false;\/\/\u6b63\u786e!<\/p> \n

12};<\/p> \n

\u8fd9\u6837\uff0c\u5373\u4f7f\u50cfCheckList\u8fd9\u6837\u7684const\u6210\u5458\u51fd\u6570\u4fee\u6539\u5b83\u4e5f\u662f\u5408\u6cd5\u7684\u3002<\/p> \n

\u4f46\u9700\u8981\u6ce8\u610f\u7684\u65f6\uff0c\u4e0d\u53ef\u6ee5\u7528mutabe\u63cf\u8ff0\u7b26\uff0c\u5982\u679c\u5728\u67d0\u4e2a\u7c7b\u4e2d\u53ea\u6709\u5c11\u6570\u4e00\u90e8\u5206\u662f\u88ab\u5141\u8bb8const\u5e38\u91cf\u51fd\u6570\u4fee\u6539\u7684\uff0c\u4f7f\u7528mutable\u662f\u518d\u5408\u9002\u4e0d\u8fc7\u7684\u3002\u5982\u679c\u5927\u90e8\u5206\u6570\u636e\u90fd\u5b9a\u4e49\u4e3amutable\uff0c\u90a3\u4e48\u6700\u597d\u5c06\u8fd9\u4e9b\u9700\u8981\u4fee\u6539\u7684\u6570\u636e\u653e\u5165\u53e6\u4e00\u4e2a\u72ec\u7acb\u7684\u5bf9\u8c61\u91cc\uff0c\u5e76\u95f4\u63a5\u5730\u8bbf\u95ee\u5b83\u3002<\/p> \n<\/div>","orderid":"0","title":"C++\uff1a\u51fd\u6570\u540e\u9762\u52a0const\u7684\u7528\u6cd5","smalltitle":"","mid":"0","fname":"c++\u7f16\u7a0b\u57fa\u7840","special_id":"0","bak_id":"0","info":"0","hits":"6940","pages":"1","comments":"0","posttime":"2017-09-19 13:06:14","list":"1505797574","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u51fd\u6570<\/A> \u540e\u9762<\/A> const<\/A> \u7528\u6cd5<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"113.108.110.181","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"C++\uff1a\u51fd\u6570\u540e\u9762\u52a0const\u7684\u7528\u6cd5","lastview":"1690395872","digg_num":"4297","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}