声明写在头文件中
定义(指的是声明在类中的函数的定义)写在与头文件相对应的.CPP文件中
例如:写一个学生成绩的类
//Student.h
#ifndef _STUDENT_H
#define _STUDENT_H
class Student
{
public:
int id;
char name[20];
double score;
void PrintScore();
}
#endif
------------------------------------
//Student.cpp
#include "Student.h"
#include <iostream>
using namespace std;
void Student::PrintScore()
{
cout << "id" << id << endl;
cout << "name" << name << endl;
cout << "score" << score << endl;
}
-------------------------------------------
//main.c
.........
.........