窗户8,铿锵
hh.h文件:
#ifndef _H_
#define _H_
#include<string>
using std::string;
static string m; // If m is defined as static, the promble of multiple definitions will be solved.
#endif
Run Code Online (Sandbox Code Playgroud)
Foo.cpp中
#include "hh.h"
int foo()
{
m = "456";
}
Run Code Online (Sandbox Code Playgroud)
bar.cpp
#include "hh.h"
int main()
{
m = "123";
}
Run Code Online (Sandbox Code Playgroud)
用-c编译foo.cpp和bar.cpp
然后,我使用"nm"检查导出符号表
00000000 b .bss
00000000 d .ctors
00000000 d .data
00000000 d .eh_frame
00000000 r .rdata
00000000 t .text
00000000 b m // a local var, as 'b'
// others
Run Code Online (Sandbox Code Playgroud)
否则,如果我定义没有限定符静态的"字符串m",例如 …
我正在阅读AbstractList的代码,其中有一个嵌套类Itr,这很好。什么混淆我是为什么的Java提供了一套方法给它的迭代器,以便它可以用来修改underlaying的集合,比如add(),remove(),set()。
您必须将集合公开给Iterator的根本原因是什么?它比通过Collection的方法修改集合更方便吗?
private class Itr implements Iterator<E> {
//......bha
public void remove() {
if (lastRet < 0)
throw new IllegalStateException();
checkForComodification();
try {
AbstractList.this.remove(lastRet);
if (lastRet < cursor)
cursor--;
lastRet = -1;
expectedModCount = modCount;
} catch (IndexOutOfBoundsException e) {
throw new ConcurrentModificationException();
}
}
}
private class ListItr extends Itr implements ListIterator<E> {
ListItr(int index) {
cursor = index;
}
public void set(E e) ///...
public void add(E e) //.....
Run Code Online (Sandbox Code Playgroud)