2016年6月11日

在同个类中non-const插入const来减少重复

摘要: class A { private: std::string a; public: A(std::string b) :a(b){} const char& operator[](int b)const { std::cout //分两部分,一部分是消掉const (static_... 阅读全文

posted @ 2016-06-11 10:56 Kooing 阅读(232) 评论(0) 推荐(0) 编辑

成员函数的const不能被修改,包括指针

摘要: #include class A { private: std::string a; public: A(std::string b) :a(b){} const char& operator[](int b)const //两个const都不能少 { return a[b]; } }; int main() { A a("he... 阅读全文

posted @ 2016-06-11 10:20 Kooing 阅读(327) 评论(0) 推荐(0) 编辑

导航