我的站点

一个系统软件工程师的随手涂鸦

Date: 十二月 22, 2015

Go语言的new函数

以下摘自The Go Programming Language

Each call to new returns a distinct variable with a unique address:
p := new(int)
q := new(int)
fmt.Println(p == q) // “false”
There is one exception to this rule: two variables whose type carries no information and is therefore of size zero, such as struct{} or [0]int, may, depending on the implementation, have the same address.
The new function is relatively rarely used because the most common unnamed variables are of struct types, for which the struct literal syntax is more flexible.

Since new is a predeclared function, not a keyword, it’s possible to redefine the name for something else within a function, for example:
func delta(old, new int) int { return new – old }
Of course, within delta, the built-in new function is unavailable.

 

C++要点笔记(1)——模板参数中的class和typename

C++中定义函数模板或者类模板,可以使用class来定义模板参数:

template <class T> ...  

也可使用typename来定义模板参数:

template <typename T> ...  

大多数情况下,二者可以交替使用。但有些情况,比如template template parameter只允许classC++1Z已经提交了关于template template parameter允许typename建议,有些编译器已经支持了)。

参考资料:
Use ‘class’ or ‘typename’ for template parameters?
Why does not a template template parameter allow ‘typename’ after the parameter list

 

《Expert C programming》中C++笔记(3)

Scope resolution operator

Capture

《Expert C programming》中C++笔记(2)

Class的定义和availability

1

2

《Expert C programming》中C++笔记(1)

面向对象的基本概念:

Capture

Powered by WordPress & Theme by Anders Norén