【C++语法】关键字

https://tlanyan.pp.ua/cpp-function-modifier-summary/

#include <bits/stdc++.h>
using namespace std;
#define PI 3.14
typedef int myint
int main(){
    const int sz = get_size();    //const objects: must be initialized  when created. Not a const expression
    constexpr int num = 315;    //constant expression: value canbe evaluated at complie time
    int arr[num];    //array dimension (as part of the array's type) must be know at compile time
    /* array 
    ** int a2[] = a1;    //error: cannot initialize one array with another
    ** int *ptr[10];    //array of ten pointers to int
    ** int (*Ptr)[10] = &arr    //point to an array of ten ints
    */
    return 0;
}

Static与Const的区别
C++ static、const 和 static const 类型成员变量声明以及初始化

const

  • const 成员变量也不能在类定义处初始化,只能通过构造函数初始化列表进行,并且必须有构造函数

static

  • outside the class, do not repeat the static keyword;
  • static member functions do not have this pointer, may not be declared as const;
  • static data members are not initialized by the constructors, they are usually defined and initialized outside the class body. (const integral type can be initialized inside the class body)
  • static data members can be the class, whereas nonstatic data members must be declared as pointers or references to the class;
  • static data members can be used as default argument
posted @ 2021-08-09 17:19  楚不予  阅读(35)  评论(0编辑  收藏  举报