您的位置:首页 > 编程语言 > C语言/C++

C++静态成员与函数

2015-07-29 16:03 218 查看
头文件:Person.h

#include<string>

using namespace std;

#pragma once

class Person

{

private:
string name;
string age;
static int count1;//static类变量

public:
const string getAge();
void setAge(string age);

    string getName();
Person(void);
~Person(void);
static int getcount();//静态函数

};

CPP文件Person::cpp

#include "StdAfx.h"

#include "Person.h"

int Person::count1=0;//static类变量初始化 需要在CPP初始化

void Person::setAge(string age){

this->age=age;

}

const string Person::getAge(){

return this->age;

}

string Person::getName()

{

return this->name;

}

Person::Person(void)

{
Person::count1++;

}

int Person::getcount(){

  
return count1;

}

Person::~Person(void)

{

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: