static 成员小记
生活随笔
收集整理的這篇文章主要介紹了
static 成员小记
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
基類有static成員時,派生類不會額外開辟一個空間存儲static成員,而是基類子類公用。
這幾天在家休息,一直為退學的事情發愁,最后還是不敢退...
#include <iostream> using namespace std;class Base { public:static int a;static void print(){cout << a << endl;}static void set(int number){a = number;} };class Derived1 : public Base { };class Derived2 : public Base { };int Base::a = 100;int main(int argc, char** argv) {// 一下都是輸出100 Base::print();Derived1::print();Derived2::print();// 在Base中將a改為99,那么后面的兩個輸出也將變成99Base::set(99);Derived1::print(); Derived2::print();return 0; }?
轉載于:https://www.cnblogs.com/cavehubiao/p/3331998.html
總結
以上是生活随笔為你收集整理的static 成员小记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python处理路径时 sh: 1:S
- 下一篇: 高频面试题1:自增边量