Sign in

gwj / po_oopc · Files

GitLab

  • Go to dashboard
  • Project
  • Activity
  • Files
  • Commits
  • Network
  • Graphs
  • po_oopc
  • examples05
  • 05-staticmember
  • static.cpp
  • Initial version
    455e0054
    Grzegorz Jabłoński authored
    2019-10-31 09:39:53 +0100  
    Browse Code »
static.cpp 365 Bytes
Edit Raw Blame History
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <iostream>
using namespace std;

class example
{
	static int a;
	int v;
public:
	static int getStatic() { return a;};
	static void setStatic(int p) {a=p;};
	example(int p): v(p){};
	int fun(){return v+a;};
};

int example::a=42;

int main()
{
	example e(27);
	example f(47);
	cout << example::getStatic()<<endl;
	f.setStatic(34);
	cout << e.fun()<<endl;
}