一个类调用另一个类的static方法

编译方法: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
using namespace std;
class CMgr
{
public:
 static void Initialize(int val);
 static int Sum(int num);
private:
 static int m_val;
};
//viewdemo.hpp
include
#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"

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 :"<  return 0;
}



你可能感兴趣的:(一个类调用另一个类的static方法)