谈谈重载(overload)覆盖(override)与隐藏、多态

news/2024/7/3 13:23:25 标签: float, 编译器, behavior, parameters, class, function
class="baidu_pl">
class="article_content clearfix">
class="htmledit_views">

摘自http://blog.csdn.net/yanjun_1982/archive/2005/09/02/470405.aspx

class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: #000000; text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">

 

class="title_txt" style="padding-right: 0px; padding-left: 1.5em; font-size: 15px; padding-bottom: 0.5em; margin: 0px; padding-top: 0px; border-bottom: #dcdcdc 2px solid; font-family: 'Microsoft yahei', verdana, sans-serif;">class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: #000000; text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">class="Apple-style-span" style="font-size: 14px; line-height: 21px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; text-align: left;">     这三个概念都是与OO中的多态有关系的。如果单是区别重载与覆盖这两个概念是比较容易的,但是隐藏这一概念却使问题变得有点复杂了,下面说说它们的区别吧。

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 0px; line-height: 19px; padding: 0px;">      class="Apple-converted-space"> 重载是指不同的函数使用相同的函数名,但是函数的参数个数或类型不同。调用的时候根据函数的参数来区别不同的函数。

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 0px; line-height: 19px; padding: 0px;">      class="Apple-converted-space"> 覆盖(也叫重写)是指在派生类中重新对基类中的虚函数(注意是虚函数)重新实现。即函数名和参数都一样,只是函数的实现体不一样。

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 0px; line-height: 19px; padding: 0px;">      class="Apple-converted-space"> 隐藏是指派生类中的函数把基类中相同名字的函数屏蔽掉了。隐藏与另外两个概念表面上看来很像,很难区分,其实他们的关键区别就是在多态的实现上。什么叫多态?简单地说就是一个接口,多种实现吧。

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 0px; line-height: 19px; padding: 0px;">      class="Apple-converted-space"> 还是引用一下别人的代码来说明问题吧(引用自林锐的《高质量C/C++编程指南》)。

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21pt; line-height: 19px; padding: 0px;">仔细看下面的代码: 

class="MsoNormalTable" style="margin: 0px; border-collapse: collapse; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; padding: 0px;" border="1" cellspacing="0" cellpadding="0">

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21pt; line-height: 19px; padding: 0px;">#include <iostream.h>  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 0px; line-height: 19px; padding: 0px;">   class="Apple-converted-space"> class Base  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21.25pt; line-height: 19px; padding: 0px;"> 

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21.25pt; line-height: 19px; padding: 0px;">public:  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 0px; line-height: 19px; padding: 0px;">   class="Apple-converted-space"> virtualclass="Apple-converted-space"> void f(class="tags" href="/tags/FLOAT.html" title=float>float x){ cout << "Base::f(class="tags" href="/tags/FLOAT.html" title=float>float) " << x << endl; }  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 42.5pt; text-indent: 21.25pt; line-height: 19px; padding: 0px;">void g(class="tags" href="/tags/FLOAT.html" title=float>float x){ cout << "Base::g(class="tags" href="/tags/FLOAT.html" title=float>float) " << x << endl; } 

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 0px; line-height: 19px; padding: 0px;">           class="Apple-converted-space"> void h(class="tags" href="/tags/FLOAT.html" title=float>float x){ cout << "Base::h(class="tags" href="/tags/FLOAT.html" title=float>float) " << x << endl; }  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21pt; line-height: 19px; padding: 0px;">};  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 0px; line-height: 19px; padding: 0px;">   class="Apple-converted-space"> class Derived : public Base 

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21.25pt; line-height: 19px; padding: 0px;"> 

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21.25pt; line-height: 19px; padding: 0px;">public:  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 0px; line-height: 19px; padding: 0px;">   class="Apple-converted-space"> virtualclass="Apple-converted-space"> void f(class="tags" href="/tags/FLOAT.html" title=float>float x){ cout << "Derived::f(class="tags" href="/tags/FLOAT.html" title=float>float) " << x << endl; }  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 42.5pt; text-indent: 21.25pt; line-height: 19px; padding: 0px;">void g(int x){ cout << "Derived::g(int) " << x << endl; } 

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 0px; line-height: 19px; padding: 0px;">           class="Apple-converted-space"> void h(class="tags" href="/tags/FLOAT.html" title=float>float x){ cout << "Derived::h(class="tags" href="/tags/FLOAT.html" title=float>float) " << x << endl; } 

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21pt; line-height: 19px; padding: 0px;">};  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21pt; line-height: 19px; padding: 0px;">看出什么了吗?下面说明一下:

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21pt; line-height: 19px; padding: 0px;">1)函数Derived::f(class="tags" href="/tags/FLOAT.html" title=float>float)覆盖了Base::f(class="tags" href="/tags/FLOAT.html" title=float>float)。  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21pt; line-height: 19px; padding: 0px;">2)函数Derived::g(int)隐藏了Base::g(class="tags" href="/tags/FLOAT.html" title=float>float),而不是重载。  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21pt; line-height: 19px; padding: 0px;">3)函数Derived::h(class="tags" href="/tags/FLOAT.html" title=float>float)隐藏了Base::h(class="tags" href="/tags/FLOAT.html" title=float>float),而不是覆盖。
 
 

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 21.8pt; text-indent: 0px; line-height: 19px; padding: 0px;">      class="Apple-converted-space"> 嗯,概念大概明白了,但是在实际的编程中,我们会因此遇到什么问题呢?再看下面的代码:

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 21.8pt; text-indent: 0px; line-height: 19px; padding: 0px;">void main(void)  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 21.8pt; text-indent: 0px; line-height: 19px; padding: 0px;"> 

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 30.95pt; text-indent: 0px; line-height: 19px; padding: 0px;">Derived class="Apple-converted-space"> d;  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 30.95pt; text-indent: 0px; line-height: 19px; padding: 0px;">Base *pb = &d;  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 30.95pt; text-indent: 0px; line-height: 19px; padding: 0px;">Derived *pd = &d; 
 

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 30.95pt; text-indent: 0px; line-height: 19px; padding: 0px;">// Good : class="tags" href="/tags/BEHAVIOR.html" title=behavior>behavior depends solely on type of the object  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 30.95pt; text-indent: 0px; line-height: 19px; padding: 0px;">pb->f(3.14f);class="Apple-converted-space"> // Derived::f(class="tags" href="/tags/FLOAT.html" title=float>float) 3.14  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 30.95pt; text-indent: 0px; line-height: 19px; padding: 0px;">pd->f(3.14f);class="Apple-converted-space"> // Derived::f(class="tags" href="/tags/FLOAT.html" title=float>float) 3.14  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 30.95pt; text-indent: 0px; line-height: 19px; padding: 0px;">// Bad : class="tags" href="/tags/BEHAVIOR.html" title=behavior>behavior depends on type of the pointer  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 30.95pt; text-indent: 0px; line-height: 19px; padding: 0px;">pb->g(3.14f);class="Apple-converted-space"> // Base::g(class="tags" href="/tags/FLOAT.html" title=float>float) 3.14  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 30.95pt; text-indent: 0px; line-height: 19px; padding: 0px;">pd->g(3.14f);class="Apple-converted-space"> // Derived::g(int) 3       class="Apple-converted-space"> (surprise!)  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 30.95pt; text-indent: 0px; line-height: 19px; padding: 0px;">
// Bad : class="tags" href="/tags/BEHAVIOR.html" title=behavior>behavior depends on type of the pointer 
 

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 30.95pt; text-indent: 0px; line-height: 19px; padding: 0px;">pb->h(3.14f);class="Apple-converted-space"> // Base::h(class="tags" href="/tags/FLOAT.html" title=float>float) 3.14     class="Apple-converted-space"> (surprise!)  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 30.95pt; text-indent: 0px; line-height: 19px; padding: 0px;">pd->h(3.14f);class="Apple-converted-space"> // Derived::h(class="tags" href="/tags/FLOAT.html" title=float>float) 3.14  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt; text-indent: 21pt; line-height: 19px; padding: 0px;">

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 21pt; text-indent: 21pt; line-height: 19px; padding: 0px;">在第一种调用中,函数的行为取决于指针所指向的对象。在第二第三种调用中,函数的行为取决于指针的类型。所以说,隐藏破坏了面向对象编程中多态这一特性,会使得OOP人员产生混乱。  

class="MsoNormal" style="font-size: 13px; margin: 0cm 0cm 0pt 21pt; text-indent: 21pt; line-height: 19px; padding: 0px;">不过隐藏也并不是一无是处,它可以帮助编程人员在编译时期找出一些错误的调用。但我觉得还是应该尽量使用隐藏这一些特性,该加virtual时就加吧。


c++ 重载 覆盖 隐藏的区别和执行方式

 
 
成员函数被重载的特征
(1)相同的范围(在同一个类中);class="Apple-converted-space"> 
(2)函数名字相同;class="Apple-converted-space"> 
(3)参数不同;class="Apple-converted-space"> 
(4)virtual 关键字可有可无。class="Apple-converted-space"> 
覆盖是指派生类函数覆盖基类函数,特征是
(1)不同的范围(分别位于派生类与基类);class="Apple-converted-space"> 
(2)函数名字相同;class="Apple-converted-space"> 
(3)参数相同;class="Apple-converted-space"> 
(4)基类函数必须有virtual 关键字。class="Apple-converted-space"> 
“隐藏”是指派生类的函数屏蔽了与其同名的基类函数,规则如下
(1)如果派生类的函数与基类的函数同名,但是参数不同。此时,不论有无virtual关键字,基类的函数将被隐藏(注意别与重载混淆)。class="Apple-converted-space"> 
(2)如果派生类的函数与基类的函数同名,并且参数也相同,但是基类函数没有virtual 关键字。此时,基类的函数被隐藏(注意别与覆盖混淆)class="Apple-converted-space"> 
3种情况怎么执行:
1。重载:看参数
2。隐藏:用什么就调用什么
3。覆盖:调用派生类

 

class="post" style="margin: 0px; padding: 0px;">

重载(overload),覆盖(override),隐藏(hide)的区别  
http://www.cppblog.com/zgysx/archive/2007/03/12/19662.html 

写正题之前,先给出几个关键字的中英文对照,重载(overload),覆盖(override),隐藏(hide)。在早期的C++书籍中,可能翻译的人不熟悉专业用语(也不能怪他们,他们不是搞计算机编程的,他们是英语专业的),常常把重载(overload)和覆盖(override)搞错!

  我们先来看一些代码及其编译结果。

  实例一:
  #include "stdafx.h"
  #include <iostream.h>

  class CB
  {
  public:
     void f(int)
     {
        cout << "CB::f(int)" << endl;
     }
  };

  class CD : public CB
  {
  public:
     
void f(int,int)
     {
        cout << "CD::f(int,int)" << endl;
     }
     void test()
     {
       f(1);
     }
  };

 int main(int argc, char* argv[])
 {
    return 0;
 }
编译了一下
error C2660: 'f' : function does not take 1 class="tags" href="/tags/PARAMETERS.html" title=parameters>parameters


结论:在类CD这个域中,没有f(int)这样的函数,基类中的void f(int)被隐藏

  如果把派生CD中成员函数void f(int,int)的声明改成和基类中一样,即f(int),基类中的void f(int)还是一样被覆盖,此时编译不会出错,在函数中test调用的是CD中的f(int) 

  所以,在基类中的某些函数,如果没有virtral关键字,函数名是f(参数是什么我们不管),那么如果在派生类CD中也声明了某个f成员函数,那么在类CD域中,基类中所有的那些f都被隐藏。
  如果你比较心急,想知道什么是隐藏,看文章最后的简单说明,不过我建议你还是一步一步看下去。

  我们刚才说的是没有virtual的情况,如果有virtual的情况呢??
  实例二:

#include "stdafx.h"
#include <iostream.h>

class CB
{
public:
   
virtual void f(int)
   {
      cout << "CB::f(int)" << endl;
   }
};

class CD : public CB
{
public:
   
void f(int)
   {
      cout << "CD::f(int)" << endl;
   }
};

int main(int argc, char* argv[])
{
  return 0;
}

  这么写当然是没问题了,在这里我不多费口舌了,这是很简单的,多态,虚函数,然后什么指向基类的指针指向派生类对象阿,通过引用调用虚函数阿什么的,属性多的很咯,什么??你不明白??随便找本C++的书,对会讲多态和虚函数机制的哦!!
  这种情况我们叫覆盖(override)!覆盖指的是派生类的虚拟函数覆盖了基类的同名且参数相同的函数!
  在这里,我要强调的是,这种覆盖,要满足两个条件
 (a)有virtual关键字,在基类中函数声明的时候加上就可以了
 (b)基类CB中的函数和派生类CD中的函数要一模一样,什么叫一模一样,函数名,参数,返回类型三个条件
  有人可能会对(b)中的说法质疑,说返回类型也要一样??
  是,覆盖的话必须一样,我试了试,如果在基类中,把f的声明改成virtual int f(int),编译出错了
  error C2555: 'CD::f' : overriding virtual function differs from 'CB::f' only by return type or calling convention
  所以,覆盖的话,必须要满足上述的(a)(b)条件

  那么如果基类CB中的函数f有关键字virtual ,但是参数和派生类CD中的函数f参数不一样呢,
实例三:
  #include "stdafx.h"
#include <iostream.h>

class CB
{
 public:
    virtual  void f(int)
   {
      cout << "CB::f(int)" << endl;
   }
};


class CD : public CB
{
public:
    void f(int,int)
   {
     cout << "CD::f(int,int)" << endl;
   }

   void test()
   {
      f(1);
   }
};

int main(int argc, char* argv[])
{
 return 0;
}

编译出错了,
 error C2660: 'f' : function does not take 1 class="tags" href="/tags/PARAMETERS.html" title=parameters>parameters
  咦??好面熟的错??对,和实例一中的情况一样哦,结论也是基类中的函数被隐藏了。

  通过上面三个例子,得出一个简单的结论
如果基类中的函数和派生类中的两个名字一样的函数f
满足下面的两个条件
(a)在基类中函数声明的时候有virtual关键字
(b)基类CB中的函数和派生类CD中的函数一模一样,函数名,参数,返回类型都一样。
那么这就是叫做覆盖(override),这也就是虚函数,多态的性质

那么其他的情况呢??只要名字一样,不满足上面覆盖的条件,就是隐藏了。

下面我要讲最关键的地方了,好多人认为,基类CB中的f(int)会继承下来和CD中的f(int,int)在派生类CD中构成重载,就像实例一中想像的那样。
  对吗?我们先看重载的定义
  
重载(overload):
  必须在一个域中,函数名称相同但是函数参数不同,重载的作用就是同一个函数有不同的行为,因此不是在一个域中的函数是无法构成重载的,这个是重载的重要特征
  必须在一个域中,而继承明显是在两个类中了哦,所以上面的想法是不成立的,我们测试的结构也是这样,派生类中的f(int,int)把基类中的f(int)隐藏了
  所以,相同的函数名的函数,在基类和派生类中的关系只能是覆盖或者隐藏。

  在文章中,我把重载和覆盖的定义都给了出来了,但是一直没有给隐藏的定义,在最后,我把他给出来,这段话是网上google来的,比较长,你可以简单的理解成,在派生类域中,看不到基类中的那个同名函数了,或者说,是并没有继承下来给你用,呵呵,如实例一 那样。
  

隐藏(hide):
指的是派生类的成员函数隐藏了基类函数的成员函数.隐藏一词可以这么理解:在调用一个类的成员函数的时候,class="tags" href="/tags/BianYiQi.html" title=编译器>编译器会沿着类的继承链逐级的向上查找函数的定义,如果找到了那么就停止查找了,所以如果一个派生类和一个基类都有同一个同名(暂且不论参数是否相同)的函数,而class="tags" href="/tags/BianYiQi.html" title=编译器>编译器最终选择了在派生类中的函数,那么我们就说这个派生类的成员函数"隐藏"了基类的成员函数,也就是说它阻止了class="tags" href="/tags/BianYiQi.html" title=编译器>编译器继续向上查找函数的定义.


class="Apple-interchange-newline" />

class="MsoNormal" style="margin: 0cm 0cm 0pt;">

class="MsoNormal" style="margin: 0cm 0cm 0pt;">class="apple-style-span">class="apple-style-span">

class="apple-style-span"> 

class="MsoNormal" style="margin: 0cm 0cm 0pt;">class="apple-style-span">摘自:class="apple-style-span">http://blog.csdn.net/yakihappy/archive/2009/03/11/3979333.aspx

class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 18pt; line-height: 14.25pt; text-align: left; mso-pagination: widow-orphan;" align="left">多态性是指在一个程序中同名的不同方法共存的情况,允许不同类的对象对同一消息作出不同响应

class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 18pt; line-height: 14.25pt; text-align: left; mso-pagination: widow-orphan;" align="left">静态多态性即是编译时的多态 这种多态采用函数重载(模板)来实现,class="tags" href="/tags/BianYiQi.html" title=编译器>编译器对对象静态绑定,编译之后就决定了调用哪一个成员函数。覆盖:在子类中直接定义的和父类同名的属性和方法,在子类的使用中, 子类覆盖父类 重载:在同一个类中可以有多个同名的方法(不同的形参,不同的实现)。 调用时根据形参的个数和类型来决定调用那个方法,如多个构造函数的重载。在使用方法重载时无法在同一个类中声明签名(方法名、参数数目、参数类型)相同但返回类型不同的方法。 将方法重载称为静态方法绑定或先期绑定,这是由于在编译时class="tags" href="/tags/BianYiQi.html" title=编译器>编译器会根据参数的类型和数目来决定调用哪个方法,而不是在执行时决定。

class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 18pt; line-height: 14.25pt; text-align: left; mso-pagination: widow-orphan;" align="left">动态多态性是由继承和虚函数实现的,class="tags" href="/tags/BianYiQi.html" title=编译器>编译器对对象动态绑定,具体调用哪一个函数只有到执行的时候才知道。C++中,多态通过虚函数实现,Java使用abstract类实现多态。

class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 18pt; line-height: 14.25pt; text-align: left; mso-pagination: widow-orphan;" align="left">动态多态如:加工厂模式的代码结构,里面有基类,在基类里面定义了一个虚函数,然后这个虚函数的多个具体的实现是在基类的各个派生类里面实现的。在调用的地方还是同一个函数调用,然后根据具体的场合调用不同的对象中的相应的函数,这种代码形式实现了运行时的动态

 

class="title_txt" style="padding-right: 0px; padding-left: 1.5em; font-size: 15px; padding-bottom: 0.5em; margin: 0px; padding-top: 0px; border-bottom: #dcdcdc 2px solid; font-family: 'Microsoft yahei', verdana, sans-serif;">而关于多态还有一比较简单的描述:

class="MsoNormal" style="margin: 0cm 0cm 0pt;">class="apple-style-span">基类有虚函数的时候,类中有虚函数指针,指向class="apple-style-span">vtable,class="apple-style-span">class="apple-style-span">vtableclass="apple-style-span">中是基类的函数实现版本。如果子类有自己的实现,会在自己的虚函数表中替换子类的实现版本。当通过指针访问时候,通过class="apple-style-span">vptrclass="apple-style-span">定位到的函数就是具体的类的实现版本。就是多态。


http://www.niftyadmin.cn/n/739428.html

相关文章

Apache模块开发

参考&#xff1a;http://blog.csdn.net/deally/article/details/4290842 第一步 使用采用Apache只带的工具apxs产生一个模板Helloword模块 apxs -g -n hello这样就会在当前目录产生一个Hello文件夹进入hello文件夹&#xff0c;修改mod_hello.c文件 里面有hello_handler函数&am…

PELCO-D与PELCO-P协议介绍

摘自http://guojun0681.blog.163.com/blog/static/10051312008920104153565/ PELCO-D与PELCO-P协议介绍 一般控制协议都由硬件或软件商编制在程序里面&#xff0c;我们只需要通过相关的控制设备来进行操作。但是作为一个从事监控行业的技术人员&#xff0c;往往会遇到除了电脑…

ap_hook_handler的定义在哪?

近日在看apache的源码&#xff0c;在他的module的定义中&#xff0c;ap_hook_handler是一个非常重要的函数。用来在apache中注册你的自定义module中的callback函数。 遍搜ap_hook_handler&#xff0c;寻不得在哪定义的。最后发现&#xff0c;这家伙把所有的hook函数都定义在宏里…

Find命令用法

Find命令用法 %find . ctime 0 -print //搜尋今天修改過的所有檔 %find . -name *.bak -exec rm {}\ //搜尋加刪除 %find . \(-name *.txt -ctime 7\) -print //搜尋7天前修改過的txt檔 利用Find命令改變所有權&#xff0c;想要改變當前目錄下所有檔的所有權,可以這樣: fi…

转:编写跨平台的软件入门——有关字节对齐

标题&#xff1a;编写跨平台的软件入门——有关字节对齐2008-03-18 09:40:29一&#xff0c; 为什么要跨平台&#xff1f;你想过把你的 Windows 上编写的程序在 Linux 编译运行吗&#xff0c;以及在 Mac 或其他 OS 上运行等等&#xff1f;反过来也一样&#xff1f;这…

phpMyadmin忘记密码解决办法

登陆mysql #mysql -uroot mysql mysql>UPDATE user SET PasswordPASSWORD(123456) where USERroot; mysql>FLUSH PRIVILEGES; mysql>quit #> service mysqld stop #> service mysqld start

同步对象Event的用法

首先介绍CreateEvent是创建windows事件的意思&#xff0c;作用主要用在判断线程退出&#xff0c;线程锁定方面. CreateEvent函数功能描述&#xff1a;创建或打开一个命名的或无名的事件对象.EVENT有两种状态&#xff1a;发信号&#xff0c;不发信号。 SetEvent/ResetEvent分别…

VC串口编程

VC串口编程 参考自&#xff1a; http://dev.yesky.com/401/2308901.shtml http://www.gkong.com/co/chncla/learn_detail.asp?learn_id16381 1、API描述  在WIN32 API中&#xff0c;串口使用文件方式进行访问&#xff0c;其操作的API基本上与文件操作的API一致。  一、打…