vc编程环境----多文件包含

文件1

//Point.h(头文件):
class Point{
public:
 Point(int x=0,int y=0): x(x),y(y){}
 int getX(){ return x;}
 int getY(){ return y;}
 static void showCount();
private:
 int x,y;
 static int count;
};

文件2

//Point.cpp(源文件)
#include "stdafx.h"
#include<iostream>
#include "point.h"
using namespace std;

int Point::count=0;

void Point::showCount(){
 cout<<" object count="<<count<<endl;
}
 

文件3

//7-1.cpp(源文件)
#include "stdafx.h"
#include<iostream>
#include "point.h"
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
 Point a(4,5);
 cout<<"Point A:"<<a.getX()<<","<<a.getY()<<endl;
 Point::showCount();
 return 0;
}

 

 

总结:

vc环境下,通过项目来包含多文件

                                                                    1>类定义文件(*.h);

                                                                    2>类的成员函数实现文件(*.cpp);

                                                                    3>主函数(*.cpp);

你可能感兴趣的:(职场,休闲,多文件包含)