cpp_grammar_separation - ShenYj/ShenYj.github.io GitHub Wiki

声明和实现分离

// .h
class Person {
private:
    int m_age;
public:
    void setAge(int age);
    int getAge();
    Person();
    ~Person();
};

// .cpp
#include "Person.h"

void Person::setAge(int age) {
    m_age = age;
}

int Person::getAge() {
    return m_age;
}

Person::Person() {
    m_age = 0;
}
⚠️ **GitHub.com Fallback** ⚠️