zoukankan      html  css  js  c++  java
  • C++术语

    声明( declaration )是告诉编译器某个东西的名称和类型( type ),但略去细节。

    下面是声明的例子:

    extern int x;     //对象(object )声明
    
    size_t numDigits( int number );   //函数声明( function ) 声明
    
    class Widget;    //类( class )声明 
    
    template<typename T>
    
    class  GraphNode;         //类模版( template )声明
    
     
    template<typename T>
    
    T function( T number1, T number 2);   //函数模版声明 

    定义( definition )是提供编译器一些声明所遗留的细节。

    对象( object )而言,定义是编译器为此对象分配内存。

    函数( function )函数模版( function template ) 而言,定义是提供代码本体。

    类( class )类模版( class template )而言,定义列出他们的成员。

    下面是定义的例子:

    int  x;                                         //对象的定义
    
    size_t numDigits( int number )     //函数的定义
    {
      //do something
      return 1;
    }
     
    class Widget    //类的定义
    {
      public:
        Widget();
        ~Widget();
        …
    }
    
    template< typename T >    //类模版的定义
    class  GraphNode
    {
     public:
        GraphNode();
       ~GraphNode();
      ….
    }
     
    template<typename T>
    T function( T number1, T number 2)  //函数模版的定义
    {
      return number1 + number2;
    }

    初始化( Initialization )是”给予对象初值”的过程。

    对用户自定义类型的对象而言,初始化由构造函数执行。默认( default )构造函数是一个可被调用而不带任何参数,这样的默认构造函数要么没有参数,要么就是每个参数都有缺省值。

    class  A 
    { 
    public: 
        A();                 //默认构造函数 
    };
    
    class B 
    { 
    public: 
        explicit B( int x=0, bool b=true );     //默认构造函数
    
    };
    
    class C 
    { 
    public: 
        explicit C( int x );    //不是默认构造函数,是带参数的构造函数 
    };

    上述的 class B 和 class C的构造函数都被声明为 explicit, 关于 explicit,请参考explicit浅谈。它可用来阻止隐式转换( implicit type conversions )为了防止隐式使用拷贝构造函数,但仍可以进行显示类型转换( explicit type conversions );

  • 相关阅读:
    个人关于浮动的理解
    css课堂笔记(盒子模型,标准文档流,浮动,美化)
    css和html课堂笔记
    html中的行内元素和块级元素
    css简介及常用语法
    html简介及常用功能
    权重比较
    盒模型
    css常见内联和块级元素
    Vigenère密码
  • 原文地址:https://www.cnblogs.com/staring-hxs/p/3701742.html
Copyright © 2011-2022 走看看