darlin's lin


  • 首页

  • 分类

  • 归档

  • 标签

  • 关于

  • 搜索

The hiding rule in C++

发表于 2019-09-13 | 分类于 C/C++

是什么

更里层的scope里的变量名会使外层的同名变量被隐藏,即使该名字是一个签名不一样的函数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <typeinfo>
using namespace std;

namespace A {
char x;
};

namespace B {
using namespace A;
int x;
};

int main() {
cout << typeid(B::x).name() << endl;
}

将会输出:

1
int

问题

如果在继承类里定义一个函数f, 则基类里的所有名为f的函数都将被隐藏,即使返回类型和参数不一样。

阅读全文 »

Array Left Rotation

发表于 2017-08-23 | 分类于 algorithm

A left rotation operation on an array of size n shifts each of the array’s elements 1 unit to the left. For example, if 2 left rotations are performed on array [1, 2, 3, 4, 5], then the array would become [3, 4, 5, 1, 2] .
Given an array of n integers a, and a number k, perform k left rotations on the array.

HackerRank

Here we want solutions with O(1) additional space and O(n) time complexity.

阅读全文 »

shell tips

发表于 2017-05-11 | 分类于 linux

通配符 *

shell 将通配符*替换为当前目录下的各个文件和目录,然后再传给命令。
比如ls *是ls(当前目录下的所有文件 + 当前目录下所有文件夹), 其中ls(当前目录下所有文件夹) 将会列举这些文件夹下的文件(夹)

1
2
3
4
5
6
7
8
➜ ls -p    # append '/' at the end of a directory
pkg/ tmp

➜ ls *
tmp

pkg: # list content in directory pkg
a.tgz.gpg read.sh
阅读全文 »

typedef详解

发表于 2017-05-11 | 分类于 C/C++

一行很常用的代码:

1
typedef int XX_Size_Check[(sizeof(XX)==64)? 1:-1];

很容易猜到上面这行代码是要在编译时检查XX的size,但再深究点,我们就会发现它跟我们平时typedef的写法不太一致。

阅读全文 »

hexo搭建博客全记录

发表于 2017-04-18 | 分类于 杂

why hexo

曾经尝试过用github pages搭博客,用的是isnowfy提供的框架,但是有几个缺点:

  • 发文章必须用它提供的框架,且需要将Github用户名和密码告诉它
  • 网站样式不好看,懒癌又不会自己调整
  • 网站自定义的维度比较小

最近看了几个用hexo搭的博客,功能基本满足我的需求,且颜值高,就果断折腾一波,我用的是Mac 。参考:

  • EZLippi-浮生志
  • hexo官网
  • NexT主题官网
    阅读全文 »
Lin Jian

Lin Jian

Live long and prosper.

5 日志
4 分类
6 标签
Github Mail
友情链接
  • 毒枭东
© 2017 - 2019 Lin Jian
由 Hexo 强力驱动
主题 - NexT.Mist