编译方法:gcc -c mgrdemo.cpp -o mgr.o
gcc -g mgr.o viewdemo.cpp -I. -o view
#include "MgrDemo.hpp"
void CMgr::Initialize(int val)
{
m_val = val;
int CMgr::Sum(int num)
{
return m_val + num;
}
//mgrdemo.hpp
#include <iostream>
void CMgr::Initialize(int val)
{
m_val = val;
int CMgr::Sum(int num)
{
return m_val + num;
}
//mgrdemo.hpp
#include <iostream>
using namespace std;
class CMgr
{
public:
static void Initialize(int val);
static int Sum(int num);
private:
static int m_val;
};
{
public:
static void Initialize(int val);
static int Sum(int num);
private:
static int m_val;
};
//viewdemo.hpp
include <iostream>
#include "MgrDemo.hpp"
using namespace std;
include <iostream>
#include "MgrDemo.hpp"
using namespace std;
class CViewDemo
{
public:
CViewDemo(int x)
{
m_x = x;
}
int Show();
private:
int m_x;
};
//ViewDemo.cpp
#include "ViewDemo.hpp"
{
public:
CViewDemo(int x)
{
m_x = x;
}
int Show();
private:
int m_x;
};
//ViewDemo.cpp
#include "ViewDemo.hpp"
int CViewDemo::Show()
{
CMgr::Initialize(11);
int myval = CMgr::Sum(5);
return myval+m_x;
}
int main()
{
CViewDemo view1(12);
int ret =view1.Show();
cout << "The total num is :"<<ret<<endl;
return 0;
}