在定义变量时,我们希望这个变量不会改变则使用const type
const变量定义时必须初始化
在定义函数参数时使用const修饰x,则在函数体内不可修改x.
variable的定义,当你申明一个变量的时候,计算机会将指定的一块内存空间和变量名进行绑定
,也就是说int x = 5;说“x等于5”是错误的,应该说将5赋值于名字叫做x内存地址为0x001的内存空间
.
其中存储的值为一个地址
,比如ptr的值就是名称为x的内存空间的地址dereference解引用
即*ptr
.
reference引用是一种特殊的pointer,它的内存结构与pointer相同,但是使用方法有所不同,按照C++Primer中的说法Reference即是一个别名
.
具体来说有以下三点区别
1、y作为别名reference不需要dereference解引用
操作即可获取名为y的内存空间中的地址对应的内存空间的值.
2、y作为别名,必须要初始化,在定义时时就与一个变量绑定,且生命周期中不可改变.而pointer可以灵活的重新指向新的空间.
3、y作为别名在初始化(赋值)时无需去地址如int &y=x;
,而pointer赋值时需要取地址如int* ptr= &x;
NULL
定义为((void*)0
或0
从而导致调用函数foo(NULL)
void foo(char *);
void foo(int);
会得到不同的结果(但实际上foo(NULL)的调用方式在编译时是无法通过的)
void*
隐式转换为其他类型
nullptr_t
类型的nullptr
,它可以隐式转换为任意指针类型,也可以进行等不等比较.
#include <iostream>
void foo(char *);
void foo(int);
int main() {
if(NULL == (void *)0) std::cout << "NULL == 0" << std::endl;
else std::cout << "NULL != 0" << std::endl;
foo(0);
// foo(NULL); // 编译无法通过
foo(nullptr);
return 0;
}
void foo(char *ch) {
std::cout << "call foo(char*)" << std::endl;
}
void foo(int i) {
std::cout << "call foo(int)" << std::endl;
}
在g++ main.cpp -g -std=c++14 -o a.out
命令编译compile,./a.out
运行后得到
NULL == 0
call foo(int)
call foo(char*)
所以为了更好的使用c++函数重载特性
要养成使用nullprt
的习惯
目录结构会出现在VS的左侧:
C/Cpp: Edit Configuration
将会自动生成c_cpp_properties.json
在打开目录下.
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang++",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
参数说明
(实验中该属性删掉并没有影响,所以说明编译器还是用的text.json里的命令)
常用includePath
(package name)
/include”Tasks:Configure Tasks
->Create tasks.json file from templates
->Other
将会自动生成task.json在打开目录下.{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "process",
"command": "g++",
"args": [
"${file}",
"-g",
"-o",
"a.out"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
参数说明
关于gcc
*点击虫子->点击设置->C++(GDB/LLDB)将自动在打开目录下生成launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb"
}
]
}
参数说明
根据task.json
对源文件进行预处理、编译优化、生成目标文件、链接最后得到可执行文件
根据launch.json
对可执行文件进行调试,可点击行前空白设置断点.
_posts
文件夹下新建xxxx-xx-xx-English-name.md
文件作为新的blog博客名.md
中头部标注格式new.txt
cd 上层文件夹
git add new.txt //将new.txt添加到仓库
git commit -m备注内容 //将更新提交到仓库并备注
git push -u origin master //将本地master分支推送到愿从仓库
//origin 的master分支
//-u 参数是设置origin为默认主机
git push //已有默认主机则推送到默认主机
git push origin master //一般情况
git pull origin master//把远程仓库origin的master抓下来
_posts
文件夹下新建xxxx-xx-xx-English-name.md
文件作为新的blog博客名.md
中头部标注格式— //头部标注分隔符
layout: post //对应_layouts文件夹内容
title: “hello jekyll! “
date: 2015-02-10 11:40:18 +0800
categories: jekyll //内容分类显示在主页及博客缩略图
tags: jekyll 端口 markdown //可有多个标签用空格隔开
author: Haoyang Gao //(可选)
mathjax: true //(数学)
—
头部格式设置完毕后会显示为:
现在想想也真是无心插柳的一次找实习。感觉不知不觉中自己真的进步了不少。
首先在我们机房的楼下看到了宣传海报,5.28 有一个联想服务的宣讲会,我看到有前端工程师的岗位,想试试自己的水平如何,就去听了宣讲会。
到了宣讲会现场,人不少,我坐在最后一排。开始就是一些介绍。包括 Future Leader 的介绍等。