作用: 将类的定义和实现分开之后,一个头文件可以被多个源文件调用
//
// Person.hpp
// C++primary
//
// Created by amesty on 16/5/11.
// Copyright © 2016年 travelrely. All rights reserved.
//
#ifndef Person_hpp
#define Person_hpp
#include <stdio.h>
#include <iostream>
using namespace std;
class A
{
public:
void func(int x,int y){
i=x;j=y;
} //成员函数func()是内联函数
void print(){
cout<<"两数相乘为:"<<i*j<<endl;
} //成员函数print()是内联函数
private:
int i,j;
};
#endif /* Person_hpp */
//
// Person.cpp
// C++primary
//
// Created by amesty on 16/5/11.
// Copyright © 2016年 travelrely. All rights reserved.
//
#include "Person.hpp"
int main()
{
A a;
a.func(1, 2);//调用func(1,2)内联函数等于直接将"i=1,j=2"写在这里
a.print();//调用print()内联函数等于将"cout<<"两数相乘为:"<<i*j<<endl"直接写到该行
return 0;
}