摘要: 常成员函数不能改变数据成员!#include <iostream>using namespace std;class Test {private: int a;public: int geta() { return a++; //正确! } int getConst() const { return a++; //错误!常成员函数不能改变数据成员。 }};int main(void){ return 0;} 阅读全文
posted @ 2012-12-26 11:48 helloweworld 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 静态成员函数如何初始化#include <iostream>using namespace std;class Test {private: static int statica; int b;public:// Test(): statica(1) {}; //错误!static数据成员不能通过初始化列表初始化。 Test(): b(1) {statica = 1;}; //正确。};int main(void){ return 0;}#include <iostream>using namespace std;class Test {private: static 阅读全文
posted @ 2012-12-26 11:47 helloweworld 阅读(274) 评论(0) 推荐(0) 编辑