- 类里边 类成员变量只能声明不能定义,由构造函数对其定义
- 如果类中含有常量(const属性不可改值)或引用型(定义时就得给值)的成员变量,必须通过初始化表对其初始化
- 在类的声明中给定构造函数的缺省值,类的实现里边不能给定缺省值
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
var x int | |
threads := runtime.GOMAXPROCS(0) | |
for i := 0; i < threads; i++ { | |
go func() { | |
for { x++ } | |
}() | |
} | |
time.Sleep(time.Second) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
var x, y int | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
x := []int{1, 2, 3} | |
for _, v := range x { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/tls" | |
"crypto/x509" | |
"fmt" | |
"io" | |
"log" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 定位new | |
*/ | |
#include <iostream> | |
using namespace std; | |
char g_addr[100]; | |
int main() { | |
// 把内存分配到全局区 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 判断栈的增长方向 | |
* | |
* 系统在调用函数时, 这个函数的相关信息都会出现栈之中, 比如参数、返回地址和局部变量 | |
* 入栈顺序和函数内的变量申明顺序可能不一样, 这和编译器有一定的关系 | |
* 所以不能通过一个函数内的多个变量在栈中的地址来判断栈的增长方向 | |
* | |
* 当它调用另一个函数时, 在它栈信息保持不变的情况下会把它调用那个函数的信息放到栈中 | |
* 两个函数的相关信息位置是固定的, 肯定是先调用的函数其信息先入栈, 后调用的函数其信息后入栈 | |
* 这样通过函数栈来确定栈的增长顺序 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c++ 缺省参数注意事项: | |
1.如果一个参数带有缺省值,那么它后边的所有参数必须都带有缺省值 | |
2.如果一个函数声明和定义分开,那么缺省参数只能放在声明中。因为编译器编译时看的是函数声明 | |
3.缺省参数避免和重载发生歧义 | |
c++ 中 ++i 和 i++的实现: | |
int operator++(); // 前++ | |
int operator++(int); // 后++ | |
用到哑元 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 通过3个宏和一个类型实现: | |
* va_start va_arg va_end va_list | |
* 实现: | |
* 把参数在栈中的地址记录到va_list中, 通过一个确定参数first_num确定地址然后逐个读取值 | |
* 通常也会在对第一个参数进行一些特殊处理以方便函数的实现 | |
* 比如强制指定为参数个数、指定结束参数或者像printf一样使用格式占位符来 | |
* 参数是如何获取的, 为什么要指定第一个参数: | |
* 函数的调用的参数会进行压栈处理, 而对参数的压栈是从右到左进行压栈 | |
* 因此栈顶就是第一个有名参数, 而参数和参数之间存放是连续的 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 指针的标准定义方法: | |
* type *ptr; | |
* int val; int *ptr = &val; | |
* int* val; int* *ptr = &val; | |
* 所以不论几级指针都一样, 指针就是*ptr, 一级指针type是int, 二级指针type是int*, 以此类推. | |
* | |
* 同理指向数组的指针: | |
* type *ptr; | |
* int arr[10]; int *ptr = arr; |
NewerOlder