由买买提看人间百态

topics

全部话题 - 话题: statice
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
g*********s
发帖数: 1782
1
来自主题: Programming版 - in-class static member question
The following code has compilation errors if "-DDEBUG" is not specified.
In function `StripePainter::init_tab(std::basic_string std::char_traits, std::allocator >)':
inclass_static.cpp:(.text+0xb): undefined reference to
`StripePainter::colorset'
inclass_static.cpp:(.text+0x1b): undefined reference to
`StripePainter::orig_color'
inclass_static.cpp:(.text+0x23): undefined reference to
`StripePainter::colorset'
inclass_static.cpp:(.text+0x58): undefined reference to
`StripePainte... 阅读全帖
m********5
发帖数: 17667
2
来自主题: Programming版 - C++: Static initialization dependency
fix addr? visibility? linkage? Init Destro
static local Y local internal first call app end
global Y cross units external before main app end
static global Y compiling unit internal before main app end
local N local internal each call call end
You've seen those names are very twisted.
The global/static are actually the same thing with different visibility.
They all get stored in static memory instead ... 阅读全帖
f********a
发帖数: 165
3
import java.util.HashMap;
public class MyClass {

public static HashMap hashMap = new HashMap Integer>();
private String s = new String();

public void log1(String msg1, String msg2){
synchronized(hashMap){
System.out.println(msg1);
System.out.println(msg2);
}
}

public void log2()
{
hashMap.put(new String("123"), new Integer(1));
}
public static void log3(String ms... 阅读全帖
v***s
发帖数: 1893
4
来自主题: Tennis版 - dynamic warmup vs static stretch
http://www.nytimes.com/2008/11/02/sports/playmagazine/112pewarm
Stretching: The Truth
WHEN DUANE KNUDSON, a professor of kinesiology at California State
University, Chico, looks around campus at athletes warming up before
practice, he sees one dangerous mistake after another. “They’re stretching
, touching their toes. . . . ” He sighs. “It’s discouraging.”
STRAIGHT-LEG MARCH (for the hamstrings and gluteus muscles)Kick one leg
straight out in front of you, with your toes flexed toward the sky. R... 阅读全帖
r****t
发帖数: 10904
5
item 18 (p80):
class Month {
public:
static Month Jan() { return Month(1); }
...
private:
explicit Month(int m);
};
这里的 static method 为什么不是
static Month Jan() { static Month m = Month(1); return m; }

按照 item 4 解释需要一个 local static,但是这里返回的不是 local static, 所以
每次 Month::Jan() 调用的时候都需要 create Month(1) 对象,而按 item 4 方法的
话,应该是 local static 这样只在第一次调用 Month::Jan() 的时候才创建对象。
这个的理解对不?
BTW,侯捷的 effective c++ 译的很烂,应该是机器翻译的再手修改了一下就拿出来卖
了。以前看到有人还推荐他译的哪一本来着。。
R*****l
发帖数: 310
6
来自主题: Rock版 - Static X - Cannibal 2007
【 以下文字转载自 Music 讨论区 】
发信人: ReadAll (Muziek Ziel), 信区: Music
标 题: Static X - Cannibal 2007
发信站: BBS 未名空间站 (Sat Mar 31 19:45:37 2007), 转信
乐队名称: Static X
专辑名称: Cannibal
风格类型: Alternative Metal(另类金属),Rap-Metal(说唱金属)
发行日期: 2007-04-03
压缩比率: VBR kbps (59.61 MB)
个人评价:Static-X的演唱向来被称为飙唱。听了4月份要发行的新专辑爽晕了。推荐
下载
乐队简介(转自网络):
以创作核心兼主唱/吉他手Wayne Static为首的Static-X,早期与鼓手Ken Jay在芝加哥
参与过多组乐团演出,两位因为音乐理念一拍即合,决定前往加州正式展开音乐之梦,
在那认识有日本血统的吉他手Koichi Fukada与贝斯手Tony Campos后,Static-X将金属
摇滚音韵加入电子声响,并融入黑暗深沉的哥德式调性与工业金属合而为一。
1998
N*n
发帖数: 456
7
来自主题: Java版 - Static就是个混球
最近重新在从头学Java
发现class 里面弄什么static.而且main一定得是static;
初学又必须从main method起。简直就是混蛋。
static 和非static method 对变量的调用完全不一样。。
这设计太脑残了。
如果要static不如放在class 外面好了。一定强求everything is object,
又弄static 在class里对初学者太混淆了。。
实在忍不住。。
a***e
发帖数: 1140
8
来自主题: Programming版 - static function and static variable?
用了C++一段时间了,还是没有完全弄明白。
看一个程序:
主程序:
double* obj; //只有定义。
function_sub(&obj); //调用子程序, 并把指针的地址做参量。
子程序:
static void function_sub(double **obj_p){
static double val[2]={1,2}; //为什么要static?
*obj_p=val; //让local数组返回?
}
俺不明白的是,参数 obj 只定义,没有分配内存。 当子程序调用结束时,local数组就
自动distory了,那返回的难道不是一个无效数组首地址吗? 还是因为加了static 关键
字就变成global了?
还有在这种情况子函数定义成 “static void” 有什么含义?
d****n
发帖数: 1241
9
static和const是不同的。
static是一个storage specifier, 表示两层含义,(1)linkage, (2) storage
duration. 例如有类似下面的定义:
/* global scope */
static int g; /* g的visibility是file-scope */
那么表示变量g的linkage是internal的,在你所定义的文件外是不可见的;其次g具有
static duration storage, 意思是说,g只能在程序开始的时候,初始化一次,同时,
g这个对象在程序运行的过程中都是存在的.
你也可以在一个函数里定义一个static的变量,在这种情况下,这个static变量是
function-scope的。
const是type qualifier, 表示只读性。比如
const int g;
那么g所代表的对象是只读的,对g进行任何形式的写操作(比如直接写或者通过指针)
是undefined behavior.
N***m
发帖数: 4460
10
来自主题: Java版 - static final的问题
我不明白你说的和static class有什么关系?
不知道我理解得的确不确切:)
比如
public class B {
public int k;
}
public class Main {
B b1 = new B();
B b2 = new B();
xxx x = new xxx(this.b1, 1);
xxx y = new xxx(this.b2, 2);
public static void main(final String[] args) {
final Main m = new Main();
System.out.println(m.b1.k);
System.out.println(m.b2.k);
}
private static class xxx {
private static final int[] aa = { 1, 2, 3 };// this one
public xxx(final B b, final int j) {
... 阅读全帖
N*n
发帖数: 456
11
来自主题: Java版 - Static就是个混球
I agree there are reasons for it, but what are the reasons?
I think one of the reasons is "everything is object". Also there are utility
methods such as print, etc. Those also designed as static.
The result is this is the 1st major trap for new Java learner. Over the
years, I have read several Java books and went to some Java training school,
but don't remember seeing any teacher/book really explain it clearly. I do
know that people talking about avoid static, but not much why.
But, there should... 阅读全帖
g*********s
发帖数: 1782
12
来自主题: Programming版 - c++里的函数可不可以是virtual+static
virtual call depends on the type of the object, right?
object can call static function, right?
what i'm thinking is:
class B {
virtual static void x();
};
class D: public B {
virtual static void x();
}
B* b = new D;
b->x(); // dynamic binding
B::x(); // static binding
D::x(); // static binding
it may not make sense. but i'm curious why it's disallowed. is there any
side effect by doing so?
back to my example, x = x; doesn't make sense but it's allowed, isn't
it?

how
fine.
h********n
发帖数: 1671
13
来自主题: Programming版 - static vector 怎么 initialize ?
向别人问问题起码要虚心一点,自己问的不清楚也不能责怪别人,别人来回答已经是很
热心了。
static变量可以用一个函数的返回值来初始化,可以任意复杂,也不限于class member
。但是复杂数据结构的static变量最好不要进行复杂的初始化。如果只是book
knowledge,最好是直接用char* array,不要用vector。如果必需要用有复杂
数据结构的static变量,最好是先缺省初始化为empty,然后在main()里动态的进行初
始化。
using namespace std;
struct A
{
static vector v;
static vector f(){ vector v; v.push_back("123"); v.push_back
("abc"); return v;}
};
vector A::v = A::f();
int main()
{
cout << A::v[0] << " " << A::v[1] << endl;
}
h********n
发帖数: 1671
14
来自主题: Programming版 - static vector 怎么 initialize ?
向别人问问题起码要虚心一点,自己问的不清楚也不能责怪别人,别人来回答已经是很
热心了。
static变量可以用一个函数的返回值来初始化,可以任意复杂,也不限于class member
。但是复杂数据结构的static变量最好不要进行复杂的初始化。如果只是book
knowledge,最好是直接用char* array,不要用vector。如果必需要用有复杂
数据结构的static变量,最好是先缺省初始化为empty,然后在main()里动态的进行初
始化。
using namespace std;
struct A
{
static vector v;
static vector f(){ vector v; v.push_back("123"); v.push_back
("abc"); return v;}
};
vector A::v = A::f();
int main()
{
cout << A::v[0] << " " << A::v[1] << endl;
}
r****t
发帖数: 10904
15
非 template 情况似乎比较清楚了,class template 里面的 static data
member 的定义和初始化有没有啥龟腚?
举个例子:
template
class StackWithCapacity : public stack_adapter
{
public:
typedef typename stack_adapter< Container>::size_type size_type;
private:
static const size_type capacity = 5;
};
capacity 是个 static const member, 我就直接在 class body 里面初始化了,
据 c++ primer,class body 外面还必须 define without initializer (虽然我我不这么做也能编译并运行正常). 这样我就在外面加
template
StackWithCapacity... 阅读全帖
r**u
发帖数: 1567
16
来自主题: JobHunting版 - static initialization dependency c++ (转载)
【 以下文字转载自 Programming 讨论区 】
发信人: raou (raou), 信区: Programming
标 题: static initialization dependency c++
发信站: BBS 未名空间站 (Wed Feb 6 13:38:35 2013, 美东)
Here's a common scenario: source file first.cpp define a static data member
of a class and provided an initializer for it. Source file second.cpp #
includes first.h and attempts to examine the value of the static data member
. When you execute that statement, the program crashes.The reason is the
compiler doesn't guarantee that C::i is initialized... 阅读全帖
h*****0
发帖数: 4889
17
来自主题: Java版 - static object assignment/init ?
那这个呢:
public class A {
public static final int x;
static {
\\ load(class B)
x = 1;
}
}
然后
public class B {
public static final int y;
static {
y = A.x;
}
}
b***i
发帖数: 3043
18
来自主题: Java版 - static final的问题
private class xxx extends yyy {
private static final long serialVersionUID = 31L;
上面是正确的
private static final int[] myArray = {99,-1};却不对,说不能用static
为什么?如果数组没有static, 能保证xxx的不同对象不用分别分配myArray的内存吗?
l*****o
发帖数: 214
19
I am maintaining a legacy SDK. The SDK will behave differently for different
platform. It's using a static variable and requires the static variable to
be created before any API call like the following:
Example for static variable (OLD CODE):
SDKContext.init();
VideoManager manager = new VideoManager();
public void VideoManager#search() {
SDKContext.search();
}
Components like VideoManager are all over the place. My gut feeling tells me
I should use Facade pattern instead, but can't be sure.... 阅读全帖
c********e
发帖数: 383
20
来自主题: Programming版 - static function and static variable?

this static keyword doesnt really mean much in this context. only thing it
says is that the definition is within the file scope, unless this is a member
function of a class/struct.
this static is the key for what happens, I am not saying that this code is
applausible but yes, the obj points to the val now. since it is static, it is
used as some global var now.
BTW, i dont think that this is C++ code , looks like some amature C programmer
's idea. If it is really a c++ coder, he would go with t
o******g
发帖数: 114
21
我没听说过static argument, 有空的话查查C++ 的ARM 应该可以知道答案.
static int foo() {}; 是有的,在C里面用的很普遍, static 表明这个函数
仅仅在此文件内可见, 用于防止name clash. C++虽然支持这种用法, 但是
很少这样使用.
l****i
发帖数: 43
22
try this
g++ -static-libgcc -static test.cc
if you still see some lib is dynamically linked, e.g., libc
you can try following
ln -s `g++ -print-file-name=libc.a`
then
g++ -static-libgcc -static test.cc
This may help
b*****n
发帖数: 2324
23
来自主题: Programming版 - static如何作为函数?
一道面试题:关于c++里面static的,追问了很多细节,怎么用,在哪里分配之类的
,还问到static作为函数的argument。
请问static作为函数的argument是什么意思?是说static可以作为一个function name
么?
X****r
发帖数: 3557
24
来自主题: Programming版 - in-class static member question
9.4.2 Static data members
2 The declaration of a static data member in its class
definition is not a definition and may be of an incomplete
type other than cv-qualified void. A definition shall be
provided for the static data member if it is used in the
program.
...
4 If a static data member is of const integral or const
enumeration type, its declaration in the class definition
can specify a constant-initializer which shall be an
integral constant expression. In that case, the m... 阅读全帖
g*********s
发帖数: 1782
25
来自主题: Programming版 - in-class static member question
sorry, i'm more confused.
1. the initializer should go with declaration or definition, or it
doesn't matter?
it's ok to have:
a.cpp: int x = 0; // definition.
b.cpp: extern int x; // declaration.
but is it ok to have the following?
a.cpp: int x; // definition.
b.cpp: extern int x = 0; // declaration.
2. why definition of a static variable in a class violates the ODR?
because we can define a static integral variable in a class, it seems
not a problem to allow any static variable to be defined in ... 阅读全帖
t****t
发帖数: 6806
26
来自主题: Programming版 - in-class static member question
didn't you read xentar's post? even you can write initializer to const
integral static data member, it doesn't mean you don't have to write
separate definitons.
however, in most cases, const static integral will be optimized out as
constant, and there will be no references to the symbol anymore in the link
stage. and in compilation stage, "no diagnostic required" (9.4.2 clause 5),
so in most cases you can get through without any errors. BUT, i can easily
construct a counter-example:
#include 阅读全帖
b*****e
发帖数: 474
27
来自主题: Programming版 - in-class static member question
You are right & your example is great. Thanks.
But I was referring to the fact that, given:
class A {
public:
const static int a = 1;
const static char c = 'A';
};
You definitely need to define const char A::c; in your code,
but you don't need to write const int A::a; (there is danger
of not writing this, as you have pointed out).
In other words, it seems that const static int typically will be optimized
out, but const static char does not get this treatment.
ODR notwithstanding, I see the... 阅读全帖
t****t
发帖数: 6806
28
来自主题: Programming版 - c++里的函数可不可以是virtual+static
look, virtual and static essentially contradicts each other. a method is
either non-virtual (if it is static), or non-static (if it is virtual). it
can't be both. this is very different from x=x, where x=x is probably
redundant but still makes sense.
now why it's disallowed? because virtual method calls with `this' pointer,
where static method calls without it. however c/c++ function prototype is
unique, so you can't do this.
h********n
发帖数: 1671
29
来自主题: Programming版 - static vector 怎么 initialize ?
补充一点,static的或是unnamed namespace中的全局变量可以定义在头文件中,当然
不建议这样做。整数类型的static const没问题。template的static变量和inline函数
当中的static变量,就只能定义在头文件中了。
其它情况,不是被多次初始化的风险,而是无法链接。
h********n
发帖数: 1671
30
来自主题: Programming版 - static vector 怎么 initialize ?
补充一点,static的或是unnamed namespace中的全局变量可以定义在头文件中,当然
不建议这样做。整数类型的static const没问题。template的static变量和inline函数
当中的static变量,就只能定义在头文件中了。
其它情况,不是被多次初始化的风险,而是无法链接。
c******g
发帖数: 63
31
两种情况,一个是global static,一个是local static。
有一点应该没啥疑问,就是这两种static variable的memory allocation是before the
program starts的(我的理解是进入main()函数之前)。但是经常有参考资料中看到
说是“at the compile time”--这就不太懂了,我把一个.cpp文件compile一下就把
memory给allocate了?这明显不可能嘛。
第二个问题是:它们到底是啥时候initialize的?我觉得global的static肯定是在到了
declare这个变量的那一句时initialize的,是在进入main()函数前。
那local的呢(在一个function里的)?究竟是在整个程序start之前initialize,还是
第一次访问那个函数,进入函数后到了declare这个变量的那一句时才initialize?
请诸位大虾给予详细批评指正!多谢!
y**b
发帖数: 10166
32
看了第三版(跟第二版还是有些改动)的item 18,
这个Month类是想设计成一个静态类(类似于一个全局变量)来用:
class Month {
public:
static Month Jan() { return Month(1); }
...
private:
explicit Month(int m):val(m) {}
static int val;
};
你说的两种做法效果相同(效率不同),因为整个Month类就是一个
静态类,返回值是否声明static Month应该没有影响,作者的办法
看似return local obj, 实际return static obj。
s**********g
发帖数: 139
33
来自主题: Programming版 - static initialization dependency c++
C requires static initialization to be constant, i.e. known at compile time.
When the C compiler compiles File2.c, it doesn't know what x is, thus can
not initialize y.
Different from C, C++ allows static to be lazy initialized the first time it
's used at runtime. So if you put the static in a function, it gets
initialized the first time the function is called. By doing this, it
guarantees the static is always initialized before use.
i**p
发帖数: 902
34
来自主题: Programming版 - C++: Static initialization dependency
I have questions after reading "Thinking in C++" volume 1, Chapter 10 Name
Control, section Static initialization dependency. Hopefully people here can
explain them to me.
1. Why does it mention "static objects"? In fact there is no static object
in the example code but global class objects only.
2. Because of the dependency, the C++ compiler "should" guarantee the order,
right? Otherwise it is a bug.
Here is from the book.
---------------------------------------------------------
there is no gu... 阅读全帖
a****l
发帖数: 245
35
There is a platform with embeded c++ compiler, it implements all the
function except static function, design a Singleton without using static
member variable or static function.
有什么好方法?
n***r
发帖数: 105
36
来自主题: JobHunting版 - 请问一下啥是static/dynamic heap?
一般来说没有static heap这种说法。不是说data segment吧?
能google出来的就这些了。似乎某些程序会预先跟OS reserve some static memory
heap。
To ensure predictable performance, Flash Lite reserves a fixed-sized chunk
of memory from the operating system (OS) to create what is called a static
memory heap. This memory is reserved when the player starts up and the size
is defined by the device manufacturer.
The OS (based on design by the manufacturer) can optionally provide the
player with additional memory called dynamic memory heap. Flas
v***s
发帖数: 1893
37
来自主题: Tennis版 - dynamic warmup vs static stretch
abstract
static stretching decreases muscle strength by as much as 30 percent.
recommendation
do static streching as late as possible during the warmup. someone call
static strech as muscle relaxation check up.
f*z
发帖数: 421
38
【 以下文字转载自 Programming 讨论区 】
发信人: fyz (木~花样年华), 信区: Programming
标 题: C++ static member method with default arguments
发信站: BBS 未名空间站 (Thu May 29 05:40:49 2014, 美东)
大牛,同学们,请教,static member method 可不可用default argument?比如,
enum Index
{
INDEX_A = 0,
INDEX_B
};
class foo
{
public:
static void method1( int a, int b = Index::INDEX_A);
};
编译可以过,但有什么要注意的地方?
多谢!
W******c
发帖数: 23
39
来自主题: Java版 - static vs. final
First, you need to understand the initialization sequence of a Java program
1.static initialization
All static vars and static floating blocks are run first AS IN THE SAME ORDER AS WRITTEN
in the source java program.
2.instance initialization
All instance vars and instance floating blocks are run next AS IN THE SAME ORDER AS
WRITTEN in the source java program.
3.constructor is run
The below example shows all. I am sure it will appear in SCJP:
class Test {
//case 1
final int instFin
m******t
发帖数: 2416
40
来自主题: Java版 - Singleton vs. static class?
I would not go with static. If you make it static, the coupling is permanent
. On the other hand, Spring keeps the wiring cost minimal, why not leverage
it?
In my OO fundamentalist opinion, Java should not have had static methods in
the first place. But then that's just me. 8-)
g*****g
发帖数: 34805
41
来自主题: Java版 - Singleton vs. static class?

permanent
leverage
in
I can't agree on this last one. Class like Math are just some static methods
using a namespace. No configuration, no inheritance whatsoever. Make them
static is space efficient and faster (for static binding)
c*****t
发帖数: 1879
42
来自主题: Java版 - Singleton vs. static class?
我觉得因噎废食不好。什么东西都可以被 abused 。争这挺无聊的。
就比如说,为什么 SQL driver manager 用的是 static method ?
static method 很多情况下是必须的。
至于靠 object serialization 工作的 API,如果这时候争 static vs
object ,简直是没事找事。
真正懂得编程的,都不会在这种小地方浪费时间。控制好那些 API 是
要给 exposed,那些是 hidden,考虑 extensibility 和 modulization
才是王道。具体你是用什么方法实现,who cares?说难听点,也就是
底层的 programmer 争这玩意儿。

with
the
I*******e
发帖数: 1879
43
☆─────────────────────────────────────☆
qxc (稽首已到于彼岸, 稽首能度诸世间) 于 (Tue Mar 20 22:13:27 2007) 提到:
看了半天没有觉悟。。
一 member 变量static 我理解, 可是这个 inner class 怎么能 static 呢?
☆─────────────────────────────────────☆
magicfat (魔法胖子) 于 (Tue Mar 20 22:55:13 2007) 提到:
An inner class holds an implicit reference to an instance of the enclosing
class.
A static inner class doesn't have to do with the enclosing class exception
the visibility and the class name generated, both of which are syntactical
and noth
h*****0
发帖数: 4889
44
来自主题: Java版 - static object assignment/init ?
class可以动态load吗?如果可以,会不会有:
public class A {
public static final int x;
static {
\\ load(class B)
x = 1;
}
}
然后
public class B {
static {
A.x = 2;
}
}
这种情况会怎么样?编译时错误还是运行时错误?
j*******a
发帖数: 101
45
static int a(){};
int a (static int i){}
有这么东西嘛? 多谢.
c*****e
发帖数: 34
46
来自主题: Programming版 - 问个static member function的问题
一个class,没有member variable,只有static member function.
我发现这些static member function 可以用来改变global variable的值.打个比方:
int main() {
int m=0;
classname::function1(m);
}
这个 function1 可以改变m的值,虽然不是pass by reference.我觉得比较奇怪,是不是
static member function就有这种用法?
谢谢大家!
c***d
发帖数: 996
47
☆─────────────────────────────────────☆
emerson (艾默生) 于 (Wed Apr 25 12:55:00 2007) 提到:
假设已有一个函数,已知该函数内部有一个local static变量形如:
void func(...)
{
static int x;
x = bla bla...
}
但该函数没有任何形式返回x的值或地止
现在俺被要求搞一个main(), 反复调用上述函数,在每次调用完后,在main里
dig out那个static变量x的值,但不允许对函数func做任何修改。
俺觉在整个program运行过程中x在memory里有固定地址,
理论上这个要求应该办得到,但不知道怎么搞,急问俺该怎么办?
多多感谢各位好心人指点
☆─────────────────────────────────────☆
kukutf (五脚蟹★酷酷豆腐) 于 (Wed Apr 25 12:57:53 2007) 提到:
以前有game用的工具:gb4
可以追踪变化的内存地址

☆───────────────
s***e
发帖数: 122
48
我对你对这个Warning/Error的理解有不同看法,我觉得那是因为this在new完成前是不
存在的,不过我同意你说的编译器给加上了static,嗯,我事实上同意了this在static函数里不存在:P
事实上,我用VC6, VS2008, g++ 4.3.1都测试了一下,的确operator new不管是不是
static都可以编译通过,而且连warning都没有。
我猜测可能是C++标准里面就是这么说的吧。
#include
#include
class NewTest
{
public:
NewTest() {}
virtual ~NewTest() {}

public:
void* operator new(size_t size) {
void *ptr = (void *)malloc(size);
printf("my own new\n");
return ptr;
}

void operator delete(void
t****t
发帖数: 6806
49
12.5 Free store [class.free]
1 Any allocation function for a class T is a static member (even if not
explicitly declared static).

static函数里不存在:P
b***y
发帖数: 2799
50
☆─────────────────────────────────────☆
jejune (孑孓) 于 (Mon Sep 8 20:04:56 2008) 提到:
网上搜到的代码大都类似于这样:
static T& getInstance(){
if (instance== null)
{
instance= new T();
}
}
}
return instance;
}
这样如果没有gc还得自己删掉,多线程的时候还得考虑加锁。
为什么不这样
static T& getInstance(){
static T instance;
return instance;
}
☆─────────────────────────────────────☆
xiangcjc (alwayswonde
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)