由买买提看人间百态

topics

全部话题 - 话题: valuetype
(共0页)
k***p
发帖数: 115
1
来自主题: Programming版 - 请教boost::any compile错误。
我的compiler是gcc 4.7。 多谢
$g++ testAny.cpp -o testAny
testAny.cpp: In function ‘void AnyTesting3()’:
testAny.cpp:66:54: error: no match for ‘operator=’ in ‘myPropertySet.std:
:map<_Key, _Tp, _Compare, _Alloc>::operator[], boost
::any, std::less >, std::allocator std::basic_string, boost::any> > >((* & std::basic_string(((
const char*)"BarrType"), (*(const std::allocator*)(& std::allocator<
char>()))))) = (BarrierType)... 阅读全帖
S********t
发帖数: 3431
2
来自主题: JobHunting版 - 说说你面过最难的算法coding题目
好吧,那我说清楚些
有个general tree,内部结构就是:
class Tree {
public:
void Walk(Visitor *v) {
// in preorder sequence
v->PreVisit(...);
...
// in postorder sequence
v->PostVisit(...);
...
}
private:
ValueType node_value;
vector children_;
}
class Visitor {
public:
virtual void PreVisit(const ValueType &node_value, bool is_leaf) = 0;
virtual void PostVisit(const ValueType &node_value, bool is_leaf) = 0;
}
Let's say you define your own tree data structure:
struct MyTree ... 阅读全帖
b*****n
发帖数: 2324
3
CLR via C#说C++ developer不能控制object放在heap还是stack上是胡说吧。
按照C++的做法new的就在heap上不是很好嘛,new int也在heap上。
按照C#,要想create在heap上的int,要:
int x;
object o = x;
必须要copy上去,而且boxed object又多了两个overhead fields。
C#这个设计算不算一个地道败笔。
c****n
发帖数: 21367
4
编译执行加速用的吧,new在stack上开销小速度快啊
b*****n
发帖数: 2324
5
也有int需要放在heap上的时候,你看明白我说什么了。
c**e
发帖数: 2558
6

for example?
b*****n
发帖数: 2324
7
就是boxing啊
我原文不是说了吗C#的boxing很傻,而且overhead很多。
为啥说它啥,因为C++一个new int就放在heap上了,而且没有overhead,而且让
developer自己选择初始是放在heap上还是stack上。而C#的value type初始×必须×放
在stack上。
c**e
发帖数: 2558
8
normally you would like to take advange of the .ent
garbage collector, which manages the heap for you.
for the gc to work, the objects on the heap have to
be self-describing. so an int on the managed heap
requires additional info around it. keeping value
type objects on the stack removes this overhead and
also spares the gc from having to manage these objects.
G***l
发帖数: 355
9
来自主题: Programming版 - C# is light-years ahead of Java now
Java和C#的设计思想是很类似,做的也是类似的事情。可以说C#是微软版的Java。这两
个语言也别谈谁抄袭谁,互相抄。比方说enum就是C#先有然后Java后来才有的。但是
Java的enum比C#好用。其实都是抄的前人的。但现在而言C#就是比Java更好的语言。别
说这些就是语法糖什么的,多了少了无所谓,就是这些决定了一个语言的易用性。
我以前是写Java的,这两年用C#,真的比Java顺手很多。像C#的delegate的设计真的非
常好。那些functional的东西也非常好用,大大简化代码,不止是行数变少,而且真的
可维护性好了很多。以前好几行,要写什么循环判断啊之类的一行就搞定,而且意思很
明确,看别人的代码容易了很多。linq也非常好,虽然没有这些可以写出一样功能的代
码,但就是不一样。
也别担心人滥用。C#毕竟还是个OO概念为主的静态语言,比Java还OO。int什么的也是
对象,分valuetype跟reference type而已,跟函数式也结合的很好,function也都是
对象。我们这儿我没见过有人写C#滥用那些的。这跟C++不同,那么多乱七八糟的东西
还都得用着... 阅读全帖
G***l
发帖数: 355
10
来自主题: Programming版 - 《C# 5.0 核心技术》第5版[PDF]
Java已经学了不少C#的东西,或者用某些人都说法,抄。比如Java的annotation就是学
的C#的attribute,实际上微软在COM里就有类似的东西了。
网上看到这么一句话说的很好:
C# is not a copy of Java. C# is an evolution of the C-style languages, which
Java is also part of. C# was developed after Java, and learned a lot. A lot
of what they learned came from what IS in Java and a lot of what they
learned is what is NOT in Java. Every good language (every good product
really) learns from its predecessors and competitors. They find out what
makes the other languages most suc... 阅读全帖
j******n
发帖数: 271
11
来自主题: Quant版 - 出个题
Yes it would work. Thanks for pointing that out.
placeholder is my H, and holder > is equivalent to my L
with the actual value as a member.
(共0页)