// ============================================================================ // p1c04_01_04 — 4.1.3 将成员变量设置为private // 来源:川大 C++/LinuxC wiki「02.Qt方向」 // 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用 // // --- 原文片段 [pageId:blockIdx] --- 标注出处。 // 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。 // ============================================================================ #include using namespace std; // --- 原文片段 [58954448:3] 4.1.3 将成员变量设置为private --- static void block_0() { class AccessLevels{ public: //对只读属性进行只读访问 int getReadOnly(){ return readOnly; } //对读写属性进行读写访问 void setReadWrite(int val){ readWrite = val; } int getReadWrite(){ return readWrite; } //对只写属性进行只写访问 void setWriteOnly(int val){ writeOnly = val; } private: int readOnly; //对外只读访问 int noAccess; //外部不可访问 int readWrite; //读写访问 int writeOnly; //只写访问 }; } // --- main --- int main() { block_0(); return 0; }