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
Ïà¹ØÎĵµ£º
Ëæ»úÉú³ÉÕûÊý£¬È»ºóËã³öÕý¸ºÁã
void getrand(int *a, int m)
{
int i;
srand(time(NULL));
for (i=0; i<m; i++)
{
a = rand()-rand();
}
}
int main(int argc, char* argv[])
{
  ......
µÚÒ»£ºprivate, public, protected ·ÃÎʱêºÅµÄ·ÃÎÊ·¶Î§£¬ÔÚûÓм̳еÄÇé¿öÏ£º
private£º
Ö»ÄÜÓÉ
1.¸ÃÀàÖеĺ¯Êý¡¢2.ÆäÓÑÔªº¯Êý·ÃÎÊ¡£
²»Äܱ»ÈκÎÆäËû·ÃÎÊ£¬¸ÃÀàµÄ¶ÔÏóÒ²²»ÄÜ·ÃÎÊ¡£
protected£º
¿ÉÒÔ±»1.¸ÃÀàÖеĺ¯Êý¡¢2.×ÓÀàµÄº¯Êý¡¢ÒÔ¼°3.ÆäÓÑÔªº¯Êý·ÃÎÊ¡£
µ«²»Äܱ»¸ÃÀàµÄ¶ÔÏó·ÃÎÊ¡£
public£º
¿ÉÒÔ±»1.¸ÃÀàÖе ......
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 ......
Ç°ÃæһƪÎÒÃǽéÉÜÁ˽ṹÌ壬ÕâƪÖÕÓÚÄܹ»½éÉܺ¯ÊýÁË¡£ÎªÊ²Ã´Õâô˵ÄØ£¿ÒòΪº¯Êý·Ç³£ÖØÒª¡£¾ÍÕâô¼òµ¥¡£ºÙºÙ£¡Ö®ËùÒÔÔÚÕâʱ²Å½²º¯Êý£¬ÊÇÒòΪ±¾Æª½«ÁªÏµµ½Ç°ÃæµÄÿһƪ£¬ÕâÑùº¯Êý²ÅÄÜÌåÏÖµÄ͸³¹¡£ÄÇÎÒÃǾÍÆȲ»¼°´ýµÄÇÐÈëÕýÌâ¡£
´ÓµÚһƪHelloworld¿ªÊ¼µ½ÏÖÔÚ£¬¾ÍûÓÐÍÑÀ뺯Êý¡£ÄǾÍÊÇÎÒÃǵÄmainº¯Êý¡£mainº¯ÊýÒ²ÊÇÒ»¸öÆÕͨµÄ ......