The members of a nested class have no special access to members of an enclosing class, nor to classes or functions that have granted friendship to an enclosing class; the usual access rules (clause 11) shall be obeyed. The members of an enclosing class have no special access to members of a nested class; the usual access rules (clause 11) shall be obeyed.
Example:
classE { int x; class B { }; classI {
B b; // error: E::B is private int y; void f(E* p, int i) {
p->x = i; // error: E::x is private
}
}; int g(I* p)
{ return p->y; // error: I::y is private
}
};
但是在 C++11 中,这段描述变更为:
$11.7/1 Nested classes [class.access.nest]
A nested class is a member and as such has the same access rights as any other member. The members of an enclosing class have no special access to members of a nested class; the usual access rules (Clause 11) shall be obeyed.
Example:
classE { int x; class B { }; classI {
B b; // OK: E::I can access E::B int y; void f(E* p, int i) {
p->x = i; // OK: E::I can access E::x
}
}; int g(I* p) { return p->y; // error: I::y is private
}
};
这个周末在家看吴军先生的《浪潮之巅》,爱不释手。作为一个曾经拜读过 Google 中国黑板报上“浪潮之巅”系列连载的读者,我本以为这会是本信息企业史,但阅读后发现新增的三分之一内容更精彩。我不曾想过一个技术人员的眼界会如此之广,能够从各个角度去观察和分析身处的这个行业、这个时代。我不否认对于书中的一些观点我并不完全赞同,但作者的眼界和思考能力着实让我佩服。
...if structure members are outside their valid interval, they will be normalized
(so that, for example, 40 October is changed into 9 November);...
这就意味着,对输入时间做严格的检查无法依赖于标准库中的 mktime() 函数,只能自己来进行。这应该也是 date 命令曾经改进过的地方。
$ date -d "2011-13-32" # date (coreutils) 5.2.1
Wed Feb 1 00:00:00 CST 2012
$ date -d "2011-13-32" # date (GNU coreutils) 8.5
date: invalid date `2011-13-32'
基于应用场景的数据特征,Facebook 抽象出了几个对存储系统的需求。由于描述起来有些复杂,例如 Efficient and low-latency strong consistency semantics within a data center,这些需求就不一一列举了。相比需求,更让人感兴趣的是它的那些“非需求”,总共有三条:
# 转换 Unix 时间到本地时间字符串
function ctime()
{
date -d "UTC 1970-01-01 $1 secs"
}
使用方法很简单:
$ ctime 1234567890
Sat Feb 14 07:31:30 CST 2009
对 date 命令熟悉的同学会说,date 不是已经有直接转 Unix 时间的参数了吗?
$ date -d @1234567890
Sat Feb 14 07:31:30 2009
但是不好意思的是,小弟有时候用的 date 程序好老,不支持 @ 符号。
$ date --version
date (coreutils) 5.2.1
Written by David MacKenzie.
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
PS: 写完这篇博文,我又想到了一个有趣的事情,既然很多 Linux 64 位版本的 time_t 已经是 long long 格式了,那么 date 命令有没有 year 2038 问题呢?
下面是 date (coreutils) 5.2.1 在 64 位服务器上的尝试结果:
$ date +%s -d "Tue Jan 19 11:14:07 CST 2038"
2147483647
$ date +%s -d "Tue Jan 19 11:14:08 CST 2038"
2147483648
$ date +%s -d "Tue Jan 19 11:14:09 CST 2999"
32473710849
$ ctime 2147483647
Tue Jan 19 11:14:07 CST 2038
$ ctime 2147483648
Sat Dec 14 04:51:44 LMT 1901
$ ctime 32473710849
Mon Mar 28 07:33:53 LMT 1910