zoukankan      html  css  js  c++  java
  • 基础

    以下来自cpp draft。

    声明

    extern int a;                   // declares a
    extern const int c;             // declares c
    int f(int);                     // declares f
    struct S;                       // declares S
    typedef int Int;                // declares Int
    extern X anotherX;              // declares anotherX
    using N::d;                     // declares d
    

    定义

    int a;                          // defines a
    extern const int c = 1;         // defines c
    int f(int x) { return x+a; }    // defines f and defines x
    struct S { int a; int b; };     // defines S, S​::​a, and S​::​b
    struct X {                      // defines X
      int x;                        // defines non-static data member x
      static int y;                 // declares static data member y
      X(): x(0) { }                 // defines a constructor of X
    };
    int X::y = 1;                   // defines X​::​y
    enum { up, down };              // defines up and down
    namespace N { int d; }          // defines N and N​::​d
    namespace N1 = N;               // defines N1
    X anX;                          // defines anX
    

    隐式定义的一堆函数

    C++ implementations implicitly define the default constructor ([class.default.ctor]), copy constructor, move constructor ([class.copy.ctor]), copy assignment operator, move assignment operator ([class.copy.assign]), or destructor member functions.
    C++会给类或结构体隐式定义默认构造函数,拷贝构造函数,移动构造函数,等号运算,移动运算,和析构函数。

    struct C {
      std::string s;
    };
    

    等于

    struct C {
      std::string s;
      C() : s() { }
      C(const C& x): s(x.s) { }
      C(C&& x): s(static_cast<std::string&&>(x.s)) { }
          //    : s(std​::​move(x.s)) { }
      C& operator=(const C& x) { s = x.s; return *this; }
      C& operator=(C&& x) { s = static_cast<std::string&&>(x.s); return *this; }
          //                { s = std​::​move(x.s); return *this; }
      ~C() { }
    };
    

    一次定义

    一个翻译单元不得包含多个一样的定义。

  • 相关阅读:
    php 匿名函数和闭包
    项目在线压缩js
    USACOTrainning.The Clocks
    USACOTrainning.Mother's Milk
    c# TXT文件读写
    Access以及少量Regex
    USACOTraining.Packing Rectangles
    First
    CUGBLinker and EXE
    异常处理总结
  • 原文地址:https://www.cnblogs.com/jhy16193335/p/12239556.html
Copyright © 2011-2022 走看看