C++接口与实现分离的2种方法 (C/C++)
方法一:使用另一个实现类分装类的私有成员和函数,这种方法称为Pimpl方法。
test.h
#pragma once
#include "shared_ptr.hpp"
class CTest
{
public:
CTest(void);
~CTest(void);
void DoSomething();
private:
class CTestImp;
boost::shared_ptr<CTestImp> pimpl_;
};
test.cpp
#include "Test.h"
#include <iostream>
class CTest::CTestImp
{
private:
CTestImp(CTestImp const &){}
CTestImp & operator=(CTestImp const &){}
public:
CTestImp(){}
void DoSomething();
};
void CTest::CTestImp::DoSomething()
{
// do something.
std::cout<<"Imp class do something."<<std::endl;
}
CTest::CTest(void)
{
boost::shared_ptr<CTestImp> pImp(new CTestImp);
pimpl_ = pImp;
}
CTest::~CTest(void)
{
}
void CTest::DoSomething()
{
pimpl_->DoSomething();
}
方法二:使用抽象类来实现接口与实现的分离。
x.h
#pragma once
#include <stdio.h>
#include "shared_ptr.hpp"
using namespace boost;
class X
{
public:
virtual void f() = 0;
virtual void g() = 0;
protected:
~X() { printf("~X\n");}
};
shared_ptr<X> createX();
x.cpp
#include "X.h"
#include <stdio.h>
class X_impl: public X
{
private:
X_impl(){};
X_impl(X_impl const &);
X_impl &&n
相关文档:
MS C、STL、MFC对Windows Mobile开发的支持
所有资料来自MSDN
--------------------------------------------------------------------------------
1.Mobile支持的Microsoft C
wcsncpy_s
wcscpy_s
wcscat_s
strncpy_s
strcpy_s
strcat_s
memmove_s
memcpy_s
_wsplitpath_s
_wmak ......
陆其明 译
原文:
http://www.codeproject.com/cpp/complex_declarations.asp
作者:Vikram A Punathambekar
介绍
曾经碰到过让你迷惑不解、类似于int * (* (*fp1) (int) ) [10];这样的变量声明吗?本文将由易到难,一步一步教会你如何理解这种复杂的C/C++声明:我们将从每天都能碰到的 ......
C及传统C++
#include <assert.h> //设定插入点
#include <ctype.h> //字符处理
#include <errno.h> //定义错误码
#include <float.h> //浮点数处理
#include <fstream.h> //文件输入/输出
#include <iomanip.h> //参数化输入/输出 ......
一、函数调用的基本步骤
函数调用大致包括以下几个步骤。
(1)参数入栈:将参数从右向左依次压入系统栈中。
(2)返回地址入栈:将当前代码区调用指令的下一条指令地址压入栈中,供函数返回时继续执行。
(3)代码区跳转:处理器从当前代码区跳转到被调用函数的入口处。
(4)栈帧调整:具体包括:
保存当前栈帧状态 ......
前面一篇我们介绍了结构体,这篇终于能够介绍函数了。为什么这么说呢?因为函数非常重要。就这么简单。嘿嘿!之所以在这时才讲函数,是因为本篇将联系到前面的每一篇,这样函数才能体现的透彻。那我们就迫不及待的切入正题。
从第一篇Helloworld开始到现在,就没有脱离函数。那就是我们的main函数。main函数也是一个普通的 ......