国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C++結構體與類指針知識點總結

2020-01-26 13:25:06
字體:
來源:轉載
供稿:網友

在結構體或類中, 指針訪問其成員函數或變量通過 "->" 運算符或者看代碼注釋部分, 注釋部分的操作不推薦:

#include <iostream>#include <cstring>using namespace std;struct STRUCT{  string hello;};int main(){  STRUCT *str=new STRUCT;  str->hello="Hello";//或者可以寫成: (*str).hello="Hello"  cout<<str->hello<<endl;//或者可以寫成: cout<<(*str).hello<<endl;  delete str;  return 0;}
#include <iostream>#include <cstring>using namespace std;class CLASS{public:  string hello;};int main(){  CLASS *str=new CLASS;  str->hello="Hello";//同理  cout<<str->hello<<endl;//同理  delete str;  return 0;}

備注: class中的public不可以省, struct中public可以省 ( 屬于語法部分, 不做解釋 )

關于類與結構體的指針都是這樣操作 (無論是哪種數據類型),

注意: 一定要給結構體或類指針聲明空間, 否則輸出可能會是亂碼或沒有輸出, 本人更建議使用智能指針, 免得申請釋放空間

以上就是本次介紹的關于C++結構體與類指針全部知識點內容,感謝大家的閱讀和對武林網的支持。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 津市市| 大石桥市| 天门市| 曲阳县| 武陟县| 城步| 新乡市| 大埔县| 成武县| 奉化市| 澎湖县| 施秉县| 高碑店市| 德保县| 卓尼县| 从江县| 辉县市| 江永县| 隆回县| 游戏| 珠海市| 磐安县| 皮山县| 锦州市| 麻栗坡县| 绍兴市| 中宁县| 宁武县| 南部县| 鄯善县| 寻甸| 山西省| 神木县| 吉隆县| 壤塘县| 宁化县| 易门县| 图木舒克市| 眉山市| 百色市| 称多县|