Re: [問題] 物件中的變數成員是否會被安排在連續記 …
如果是我, 會改成這樣:
http://codepad.org/z5qT4frn
假如你是讀二進位格式的檔案, OpenFile() 的地方會比較麻煩就是,
但好處就是預設值全是0了, 另外如果怕成員一多會讓code顯得雜亂,
可以新增一個靜態成員指標陣列:
class FileAnalysis
{
// ...
typedef Container FileAnalysis::*PtrToMember;
static PtrToMember const members[];
// ...
};
FileAnalysis::PtrToMember const
FileAnalysis::members[] = {
&FileAnalysis::Size,
&FileAnalysis::Format,
&FileAnalysis::Channel,
&FileAnalysis::SampleRate,
&FileAnalysis::SampleBit
};
那麼清空的部份就比較簡單:
#define each_of( c ) ((c).begin()), ((c).end())
void FileAnalysis::Reset()
{
size_t count const = sizeof(members) / sizeof(PtrToMember);
for( size_t i = 0; i != count; ++i )
std::fill( each_of(this->*members[i]), uint(0) );
}
--
★ ★ ★ ★
★ ★ ★ ███ ███ █ █▌█ ██◣ ███ ▋▋█ ★ ★ ★
█▂█ █▃█ █ ███ █▆█ █▄█ ███
★ ★ █ ◣ █ █ █ ▋██ █▆◤ ███ ███ ★ ★
Kim Jae Kyung Koh Woo Ri Cho Hyun Young Kim Ji Sook
φwindyhorse No Eul Oh Seung A Jung Yoon Hye
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.121.197.115
※ 編輯: loveme00835 來自: 221.120.2.36 (09/23 01:36)
推
09/23 08:24, , 1F
09/23 08:24, 1F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):