j*p 发帖数: 115 | 1 virtual是说函数由object的类决定的, static是说函数和属于某个类,和具体的
object无关 理论上两个没冲突啊
我看到的最make sense的解释就是 理论上可以 只不过当时设计c++的时候 没有做 因
为没有什么需求 |
|
e****d 发帖数: 895 | 2 Calling a static member function doesn't pass in "this" of
the dynamic type, which results in not being able to lookup
the correct vptr to the vtable. |
|
z***e 发帖数: 5393 | 3 如果可以,你把static method的vptr放哪里?放在class的virtual pointer table里
面? |
|
g*********s 发帖数: 1782 | 4 why not? static or not, methods are based on class, not object. |
|
|
r*******y 发帖数: 1081 | 6 it is initialization. try this
static vector v;
cout <
the output is 0, which means v is initialized with empty string. |
|
m*********g 发帖数: 646 | 7 我对你无语了。
你知道为什么要用一个static member么?你这有什么用? |
|
m*********g 发帖数: 646 | 8 that is because you have even NO idea/exp about static member, rt ? |
|
S**I 发帖数: 15689 | 9 wrap it into another class and use an object of that class as static member
instead. |
|
m*********g 发帖数: 646 | 10 what if I want this static vector to store "ABC" "DEF" "GHI" ? |
|
t****t 发帖数: 6806 | 11 now that's the correct way to ask question. initialize? with what? you have
to be specific. initialize with empty vector is initialize too, and it doesn
't matter whether you have static object or not.
experienced ppl may have guessed what you need, but most ppl won't.
now here is the answer. there is no decent way to do this in c++03. you may
define const char* array and initialize with it, but you add extra objects.
it's ugly and easy to make mistakes.
c++0x added std::initializer_list<>, whic... 阅读全帖 |
|
h**********c 发帖数: 4120 | 12 好像这样吧
some.h
class c {
static std::vector sv;
public:
}
some.cpp
std::vector c::sv ;
最少visual c++ 是这样,
如何解释呢,header 里的东西不会成为memory instance,只有cpp 里才可以。 |
|
h********n 发帖数: 1671 | 13 别人需要看的是声明,而不是定义。到.cpp里看定义才知道它是什么,这样更confuse
别人。
进入main()以后进行实质的初始化,可以保证这时所有变量都已经处在valid状态。你
这个例子用的都是库类型,还问题不大。如果某一天你换成了自己的string类,或者改
用自己的allocator,那这种静态初始化的用法就是一个定时炸弹,不知什么地方就有
可能会引用到一个还没有初始化的变量。
原则上static变量的初始状态都应该尽可能简单。把复杂的参数写进构造函数参数列表
,与用一个函数来初始化没有区别,因为构造函数也是一个函数,只是语法不同。
前面的几个答案里,初始化为empty的那个才是最好的design,有经验的人都会这样写
。其他几个答案不过是为了满足你这个奇怪的用法而凑出来的。
另一方面,如果你不打算进行动态修改的话,为什么要用vector?这时用char
*[]是最合理的。如果你打算在程序中进行动态修改的话,动态初始化自然也很正常。 |
|
|
r*******y 发帖数: 1081 | 15 it is initialization. try this
static vector v;
cout <
the output is 0, which means v is initialized with empty string. |
|
m*********g 发帖数: 646 | 16 我对你无语了。
你知道为什么要用一个static member么?你这有什么用? |
|
m*********g 发帖数: 646 | 17 that is because you have even NO idea/exp about static member, rt ? |
|
S**I 发帖数: 15689 | 18 wrap it into another class and use an object of that class as static member
instead. |
|
m*********g 发帖数: 646 | 19 what if I want this static vector to store "ABC" "DEF" "GHI" ? |
|
t****t 发帖数: 6806 | 20 now that's the correct way to ask question. initialize? with what? you have
to be specific. initialize with empty vector is initialize too, and it doesn
't matter whether you have static object or not.
experienced ppl may have guessed what you need, but most ppl won't.
now here is the answer. there is no decent way to do this in c++03. you may
define const char* array and initialize with it, but you add extra objects.
it's ugly and easy to make mistakes.
c++0x added std::initializer_list<>, whic... 阅读全帖 |
|
h**********c 发帖数: 4120 | 21 好像这样吧
some.h
class c {
static std::vector sv;
public:
}
some.cpp
std::vector c::sv ;
最少visual c++ 是这样,
如何解释呢,header 里的东西不会成为memory instance,只有cpp 里才可以。 |
|
h********n 发帖数: 1671 | 22 别人需要看的是声明,而不是定义。到.cpp里看定义才知道它是什么,这样更confuse
别人。
进入main()以后进行实质的初始化,可以保证这时所有变量都已经处在valid状态。你
这个例子用的都是库类型,还问题不大。如果某一天你换成了自己的string类,或者改
用自己的allocator,那这种静态初始化的用法就是一个定时炸弹,不知什么地方就有
可能会引用到一个还没有初始化的变量。
原则上static变量的初始状态都应该尽可能简单。把复杂的参数写进构造函数参数列表
,与用一个函数来初始化没有区别,因为构造函数也是一个函数,只是语法不同。
前面的几个答案里,初始化为empty的那个才是最好的design,有经验的人都会这样写
。其他几个答案不过是为了满足你这个奇怪的用法而凑出来的。
另一方面,如果你不打算进行动态修改的话,为什么要用vector?这时用char
*[]是最合理的。如果你打算在程序中进行动态修改的话,动态初始化自然也很正常。 |
|
D*******a 发帖数: 3688 | 23 编译生成binary的时候,把static variable的内容直接写进文件。操作系统运行的时
候,先把文件读入内存,这就等于分配了空间。
the |
|
y**b 发帖数: 10166 | 24 最后一个static想干什么呢?
第一次多调用拷贝构造函数,以后每次多调用copy assignment. |
|
r****t 发帖数: 10904 | 25 你说的没错,这里是问如果照作者解释的一样按 item 4 应该怎么办,和实际上作
者怎么办,以及实际上作者的办法 (return local obj) 是不是和使用 item 4
(local static obj) 是一回事? |
|
g*****y 发帖数: 7271 | 26 之所以这么叫,是因为在base里面的function interface(),可以调用派生
类的implementation. 所以你可以通过写derived class来customize不同
的implementation。
但是不同于virtual function,这个是在编译时绑定的,你必需明确声明派生类
来调用相应的implementation。所以叫static polymorphism。 |
|
d******3 发帖数: 70 | 27 Everyone knows how to use the Polymorphism with dynamic binding. But dynamic
binding has a run-time cost of both time and memory (virtual table). This
video demos a polymorphism with static binding, which has the benefits of
plymorphism without the cost of virtual table.
http://www.youtube.com/watch?v=-WV9vWjhI3g&list=PLE28375D4AC946 |
|
s**********g 发帖数: 139 | 28 define a static function geti and use that. make i private.
member
member
referenced |
|
t****t 发帖数: 6806 | 29 这可能是他没注意, 但是从他的目的来说, 用static (class or not) object 或者glo
bal object都没什么差别, 关键在于这些都是程序一开始需要初始化的对象. bihai说得
很清楚了, lifetime才是重要的.
the |
|
m****s 发帖数: 1481 | 30 static const char* const grades[]={"A","B","C","D","Fail"};
比较糊涂,这里两个const分别定义什么东西是constant呢?谢谢 |
|
m****s 发帖数: 1481 | 31 顺便再问下,按照从右往左读,这里这个static是指const char* 是静态的?也就是那
些字符串只初始化一次就不再变了。但是如果这一句是在一个function里,每次call这
个function,letters array里面存的地址还是重新从那些字符串那里初始化一次? |
|
n*****t 发帖数: 22014 | 32 C 是把这些全放在 data segment 里的。array 存指针,编译的时候就初始化了,运行
时候不会再动了。static const 你就理解成 define 常量好了。
C++ 应该差不多吧?俺不懂胡说的 |
|
d****n 发帖数: 1241 | 33 准确的说编译器会把没有初始化的static变量放到bss里,有初始值的,放到data
segment里 |
|
a********c 发帖数: 3 | 34 I have several .o files, I want to build them into a static library file, what
command should I use? 3X! |
|
I***a 发帖数: 704 | 35 测SRAM static noise margin
画出butterfly curves 以后,maximum squares的大小是如何计算出来的呢?
谢谢。 |
|
|
l********e 发帖数: 214 | 37 quasi-static不考虑inertia,加速度带来的效应被忽略了。当然还有其它区别。 |
|
l*******3 发帖数: 186 | 38 question:
1. given the choice between two different static replication portfolios
that
match an option's payoff, what criteria would you use to decide between
the
two?
2. what are some of the practical problems of dynamic replication?
transaction cost (so we cannot replicate too frequently).
any other concerns?
Thank you! |
|
w*s 发帖数: 7227 | 39 【 以下文字转载自 Programming 讨论区 】
发信人: wds (网虫都是loser), 信区: Programming
标 题: pls recommend a good c++ math/statics lib (besides matlab)
发信站: BBS 未名空间站 (Wed Aug 14 05:04:23 2013, 美东)
in linux |
|
e**********m 发帖数: 1960 | 40 statistics? what is statics?
gnu scientific library
boost
R standalone library |
|
|
|
|
|
w*******y 发帖数: 60932 | 45 Get a Free Uncharted 3 PS3 Static Theme when you register for e-mail updates
Theme:
http://www.unchartedthegame.com/
And get a free limited-time-only UNCHARTED 3: Drakes Deception logo PSN
Avatar with this code while supplys last.
F3E9-33NJ-JGCQ
|
|
|
|
|
|
w*******y 发帖数: 60932 | 50 Meritline
2-pack 90 Degree SATA Data Cable
$0.80 with code MLCK9F30NL1
Microphone For Multimedia And Notebook:
http://www.meritline.com/notebook-microphones---p-37744.aspx
$0.69 with code MLCK9F30NL1
High Precision Anti-Static Stainless Steel Tweezers
$0.59 with code MLCK9F30NL1
free shipping
|
|