[問題] C++結構與類別差異

看板C_and_CPP作者 (嗚啦啦)時間9年前發表 (2016/02/27 06:58), 9年前編輯推噓4(402)
留言6則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Linux (Android) 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) libstagefright frameworks/av/media/libstagefright/xxx.cpp 問題(Question): 事實上不止這部分程式碼 很多Android C++程式碼,常出現用struct代替class的狀況 偏偏struct裡面又用了建構、解構、private等功能 實在不了解這兩者(class & struct)在此有什麼不同,為何需要交替使用? 有請版上強者協助解惑... Orz -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.193.182.212 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1456556332.A.513.html ※ 編輯: wudidog (123.193.182.212), 02/27/2016 15:00:24

02/27 15:12, , 1F
在C++裡,struct與class只差在default access specifier
02/27 15:12, 1F

02/27 15:12, , 2F
struct是public,class是private
02/27 15:12, 2F

02/27 17:02, , 3F
看你想不想封裝的問題
02/27 17:02, 3F

02/27 19:35, , 4F
簡單來說,沒差
02/27 19:35, 4F

03/02 01:09, , 5F
通常struct只用在是POD的情況下
03/02 01:09, 5F

03/02 12:56, , 6F
1F 說的還有用在繼承中
03/02 12:56, 6F
文章代碼(AID): #1MqKaiKJ (C_and_CPP)