由买买提看人间百态

topics

全部话题 - 话题: obje
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
m******o
发帖数: 774
1
看上去几位都觉得中间这个参数有问题,我是拷贝的一个网上例子,原函数是:
function showhint(menucontents, obj, tipwidth){
...
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.
offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
在我的另外一个JSP(works fine)里我是这样使用showhint()的,但我的确不清楚这
儿的'this'是什么涵义,只是照猫画虎而已:
阅读全帖
l***e
发帖数: 480
2
来自主题: Programming版 - 继续请教C++重载问题,>>
like this?:
friend istream & operator>>(istream &stream, class & obj) {
i=getline(stream, obj.a, '\t');
if(i>0){
getline(stream, obj.b, '\t');
stream >> obj.c >> obj.d >> ws;
return stream;
}
}
mail()
{
while(!cin.eof()) cin>>obj;
}
p*****u
发帖数: 711
3
#include
class A {
public:
void print();
};
void A::print() {
cout << "A.print"<< endl;
}
class B: publicA {
}
int main() {
B obj;
obj.print();
return 0;
}
output is "A.print"
接下来
#include
class A {
public:
virtual void print();
};
void A::print() {
cout << "A.print"<< endl;
}
class B: publicA {
}
void B::print(){ count << "B.print" << endl;}
int main() {
B obj;
obj.print();
return 0;
}
error: no 'void B::print()' member function declared in class 'B'
如果想ov... 阅读全帖
z****e
发帖数: 54598
4
来自主题: Programming版 - oop还是跟fp是对立的
最简单例子,就不说场景
func1(Object1 obj1)
func2(Object2 obj2)
你觉得这两个是不是func1&obj1, func2&obj2两个紧密耦合了起来?
对比
obj1.func1
obj2.func2
其实是一回事
因为任何改动obj1的地方都会牵涉func1的改动
对吧?
对比
func1(Map map1)
func2(Map map2)
是不是就要更为松散呢?
这个时候你叠加func1&func2就很容易
当然一般这么理想是比较难做到的
多数时候还是这样
func1(Object obj)
func2(Object obj)
因为obj不变,所以func1(func2(obj))的叠加就很容易
但是如果obj在func1&func2中是不一样的
就变成紧耦合了,func和obj无法分离
所以fp不适合做这种一堆对象的场景,如果都是information
也就是map&list,就很容易了
沙发就在说这个,你回的一大通,我还以为你知道我在说啥呢
z****e
发帖数: 54598
5
所谓大项目,就是你一个搞不定全部的项目
或者你一个人在短时间内无法搞定所有的项目
而且往往是需要一堆人来搞的项目,统称大项目
这种项目一般都需要跟特别大的集团打交道
什么是特别大的集团?你到城里去
抬头看,看那些大厦上面的logo都是哪些公司
基本上就是这些公司了
常见的有银行,航空公司,政府,保险公司这些
这些集团基本上都养猴子
所以大项目基本上都是这些集团一个或者多个凑一起
搞出来的项目
那跟这些集团打交道,绝对不是什么一两条枪就能搞定的
多数时候需要合作,跟其他人合作
这就是大项目
那既然是合作,必然有人写代码,有人看代码
那看代码的时候最喜欢的语言,肯定是java
为啥?举个例子,你有一个InputField
java是这么定义的
InputField intfd = new ...;
而且ide可以帮忙,就是任何时候,你看到一个名词
比如这里的intfd,你看不懂,按住cmd然后点这个名词
你就可以跳到这个的声明部分,你看到声明就知道是什么了
然后如果你对这个东西的动作有兴趣
比如disableInput(),在intfd后面加一个点.
ide就会自动跳出所有跟这个intfd... 阅读全帖
z****e
发帖数: 54598
6
所谓大项目,就是你一个搞不定全部的项目
或者你一个人在短时间内无法搞定所有的项目
而且往往是需要一堆人来搞的项目,统称大项目
这种项目一般都需要跟特别大的集团打交道
什么是特别大的集团?你到城里去
抬头看,看那些大厦上面的logo都是哪些公司
基本上就是这些公司了
常见的有银行,航空公司,政府,保险公司这些
这些集团基本上都养猴子
所以大项目基本上都是这些集团一个或者多个凑一起
搞出来的项目
那跟这些集团打交道,绝对不是什么一两条枪就能搞定的
多数时候需要合作,跟其他人合作
这就是大项目
那既然是合作,必然有人写代码,有人看代码
那看代码的时候最喜欢的语言,肯定是java
为啥?举个例子,你有一个InputField
java是这么定义的
InputField intfd = new ...;
而且ide可以帮忙,就是任何时候,你看到一个名词
比如这里的intfd,你看不懂,按住cmd然后点这个名词
你就可以跳到这个的声明部分,你看到声明就知道是什么了
然后如果你对这个东西的动作有兴趣
比如disableInput(),在intfd后面加一个点.
ide就会自动跳出所有跟这个intfd... 阅读全帖
h****n
发帖数: 1093
7
来自主题: JobHunting版 - Amazon电面题目
可以呵呵
用hash先找到object 的 reference
然后直接
obj->pre->next = obj->next;
obj->next->pre = obj->pre;
free(obj);
即可。
c*****m
发帖数: 271
8
来自主题: JobHunting版 - 小弟求问LinkedIn那道Deep Iterator的题
试着写一个python的
import unittest
class DeepIterator():
def __init__(self, deep_list):
if deep_list == None:
self.iterator_stack = []
else:
self.iterator_stack = [[deep_list, 0]]
self.cur_value = None
def hasNext(self):
#the iterator stack is empty, False
if len(self.iterator_stack) == 0:
return False

#ensure hasNext() can be called many times before next()
if self.cur_value != None:
... 阅读全帖
x*******8
发帖数: 145
9
来自主题: JobHunting版 - BrightEdge及LinkedIn电面面经
Level Sum那道这个可以么?
public static int sum(List list,int level){
int sum = 0;
for(Object obj:list){
if(obj instanceof Integer){
sum+=level*(Integer)obj;
}else if(obj instanceof List){

sum+=sum((List)obj,level+1);
}
}
return sum;
}
c*********a
发帖数: 8
10
来自主题: JobHunting版 - 两道题,祝大家新年快乐!
Code for G question:
public class Solution {
public static class Pair implements Comparable{
int val;
int count;
public Pair(int val, int count) {
this.val = val;
this.count = count;
}
@Override
public int hashCode() {
return val + count * 3;
}
@Override
public boolean equals(Object obj) {
if ( obj == null ) { return false;}
if ( obj.getClass() != this.get... 阅读全帖
h***s
发帖数: 45
11
来自主题: JobHunting版 - LinkedIn 面试题讨论
这样可以吗?好像就是直接的DFS了。
public int getSum(List list)
{
return dfs(list, 1);
}
@SuppressWarnings("unchecked")
public int dfs(List list, int level)
{
if ( list == null ) return 0;

int sum = 0;
for ( Object obj : list )
{
if ( obj instanceof Integer )
{
sum += ((Integer) obj) * level;
}
else if ( obj instanceof List)
{
sum += dfs(((List) obj), level + 1);
}
}

return sum;
}
s******g
发帖数: 755
12
【 以下文字转载自 Apple 讨论区 】
发信人: faucetQ (fq), 信区: Apple
标 题: [Mac Dev]整了个ObjectiveC的笔记,看看气氛对得上不
发信站: BBS 未名空间站 (Mon Feb 2 21:38:18 2009), 转信
整了个类似ObjectiveC学习笔记的东西,发上来大伙看看有兴趣不。
修改了一点,增加了NSAutoreleasePool的内容。
增加了NSString内容。
===========俺系分隔线==================
本文假设读者有基本的C编程能力,如果有C++或者Java的背景会更容易理解但是不是必须。
ObjectiveC基本语法
消息
在objectiveC中,向一个对象发送一个消息的语法为
[ obj method:parameter];
类似的功能在C++中写作
obj->method(parameter);
在java中写作
obj.method(parameter);
在smalltalk中写作
obj method:parameter
显而易见objectiveC和smalltalk... 阅读全帖
g****s
发帖数: 306
13
BUG reports:
Too long evaluation. Execution aborted.
program: adm/obj/simul_efun.c, object: adm/obj/simul_efun, file: /adm/simul_efun/gender.c:13
' command_hook' in ' feature/command.c' (' obj/user#849') /feature/command.c:43
' main' in ' cmds/usr/quit.c' (' cmds/usr/quit') /cmds/usr/quit.c:33
' do_drop' in ' cmds/std/drop.c' (' cmds/std/drop') /cmds/std/drop.c:64
' message_vision' in 'adm/obj/simul_efun.c' (' adm/obj/simul_efun') /adm/simul_efun/
g**u
发帖数: 13
14
来自主题: WmGame版 - 哪有LINUX下的Mud client ?
谢谢,我有了,不过我在安装mud (fy3 ) 在freeBSD 2.2.7上的时候
碰钉子了,谁能帮帮我?
下面是报错信息和config.fy3的前部分内容
% ./driver config.fy3 &
[1] 17313
% using config file: config.fy3
Initializing internal tables....
----------------------------------------------------------------------------
风云三(本地) (MudOS v21.7) starting up on FreeBSD - Sun Mar 21 16:58:10 1999
Connected to address server on localhost port 9990
adm/simul_efun/file.c line 20: Undefined function seteuid
adm/simul_efun/object.c line 57: Undefined function getuid
ad... 阅读全帖
f*****Q
发帖数: 1912
15
整了个类似ObjectiveC学习笔记的东西,发上来大伙看看有兴趣不。
修改了一点,增加了NSAutoreleasePool的内容。
增加了NSString内容。
===========俺系分隔线==================
本文假设读者有基本的C编程能力,如果有C++或者Java的背景会更容易理解但是不是必须。
ObjectiveC基本语法
消息
在objectiveC中,向一个对象发送一个消息的语法为
[ obj method:parameter];
类似的功能在C++中写作
obj->method(parameter);
在java中写作
obj.method(parameter);
在smalltalk中写作
obj method:parameter
显而易见objectiveC和smalltalk的语法基本是相同的。
当有两个或者两个以上的参数时,通常试用以的语法
[ obj method:parameter1 WithSecondParameter:parameter2];
定义一个类的代码放在一个.h文件中,下面是一个例子。
//macdevexample1.h
f*****Q
发帖数: 1912
16
整了个类似ObjectiveC学习笔记的东西,发上来大伙看看有兴趣不。
修改了一点,增加了NSAutoreleasePool的内容。
增加了NSString内容。
===========俺系分隔线==================
本文假设读者有基本的C编程能力,如果有C++或者Java的背景会更容易理解但是不是必须。
ObjectiveC基本语法
消息
在objectiveC中,向一个对象发送一个消息的语法为
[ obj method:parameter];
类似的功能在C++中写作
obj->method(parameter);
在java中写作
obj.method(parameter);
在smalltalk中写作
obj method:parameter
显而易见objectiveC和smalltalk的语法基本是相同的。
当有两个或者两个以上的参数时,通常试用以的语法
[ obj method:parameter1 WithSecondParameter:parameter2];
定义一个类的代码放在一个.h文件中,下面是一个例子。
//macdevexample1.h
... 阅读全帖
T*******x
发帖数: 8565
17
来自主题: Java版 - [转载] Java 1.5 Generic 问题
Object obj = new Object();
Integer integer = (Integer) obj;
String string = (String) obj;
HashMap map = (HashMap) obj;
HashMap stringMap = (HashMap) obj;
以上的4个cast,只有最后一个给出warning,为什么?

downcast.
q*********u
发帖数: 280
18
来自主题: Java版 - a fun coding question
package multithread;
class SynObject{
public int counter;
public SynObject(){
counter = 0;
}
public SynObject(int cnt){
counter = cnt;
}
}
class Thread3 extends Thread{
public SynObject obj;

public Thread3(SynObject obj){
this.obj = obj;
}

public void run(){
synchronized(obj){
System.out.println("Thread3, before while() lo
m****r
发帖数: 6639
19
来自主题: Java版 - multi-threading guru们 (转载)
i re-write job2 like this:
class job2 {
run() {
synchronize (obj) {
obj.method2;
obj.set method2 done;
if (need to wake up only one thread) {
obj.notify();
} else {
obj.notifyAll();
}
}
}
S*A
发帖数: 7142
20
you can try dir(obj) to get a list of the member of the obj.
Depend on how the obj is implemented. dir(obj) might not get
all the member if the obj has its own access function.
i**p
发帖数: 902
21
Which one is the a valid function prototype? Is it C only?
A. template void Display(std::vector& obj);
B. template void Display(std::vector& obj);
C. template void Display(std::vector& obj);
D. template void Display(std::vector& obj);
E. template void Display(std::vector& obj);
p*****u
发帖数: 711
22
但如果不定义B::print.
B obj;
obj.print就会调用A::print, 是否可以这样理解,调用一个obj.print()时,先在
class
B中找print(),如果没有定义,再在class B的supclass 即class A中找? 函数调用时
这个查
找是如何实现的?
#include
class A{
public:
void print();
};
void A::print() {
cout << "A.print" << endl;
}
class B : public A {
public:
void print();
};
int main() {
B obj;
obj.print();
return 0;
}
给出的error msg是
In function `main':
undefined reference to `B::print()'
说明在B中定义print()之后,A的print就被屏蔽了?compiler在定义B::print()时,做
了什么
事情?
望大侠们解惑。。。
m*****r
发帖数: 37
23
来自主题: Programming版 - Java弱弱请救几个小问题
如果c++先定义一个ptr; Obj *ptr;
就相当于java定义的ref,假如两个能共享的话: Obj ref = *ptr; (觉得想明白了,这里
还是感觉很怪啊)
或者java定义了ref, Obj ref = new Obj();
那c++的ptr版本就该是: Obj *ptr = &ref;
多谢帮我理一遍.我应该是理解对了,可是因为没时间读文档,心里还很心虚...
a*****e
发帖数: 1700
24
来自主题: Programming版 - oop还是跟fp是对立的
我觉得你要说的是:
func1(Object obj)
func2(Object obj)
这种写法,你在 func1 和 func2 的 body 里面只知道对象是 Object,从而不能谈论
更多。
换成 OO 的方式, obj->func1() obj->func2(),只需要知道 Object class 里面有
func1 和 func2 两个成员函数,而不需要知道 obj 具体是 Object class 还是它的
sub class。通过 sub class 来 overload method 可以实现更多功能。
这是你的意思,对不对?
这种 OO 里面的做法换成用 Haskell:
class ObjectClass a where
func1 :: a -> ...
func2 :: a -> ...
type ObjectType1 = ...
type ObjectType2 = ...
instance ObjectClass ObjectType1 where
func1 = ...
func2 = ...
instance ObjectC... 阅读全帖
z****e
发帖数: 54598
25
来自主题: Programming版 - 1st class citizen
举个例子,一个obj,三个func1,func2,func3
顺序执行func1, func2, func3
有下面两种方式书写,你觉得哪种好?
第一种
obj.func1().func2().func3();
优化一下,根据.做换行
obj.func1()
.func2()
.func3();
第二种
func3(func2(func1(obj)));
优化下,缩进,换行
func3(
func2(
func1(obj)));
哪种更好?
A*******e
发帖数: 2419
26
来自主题: Programming版 - 关于针对接口的unit test
理论上说,unit tests只应该针对接口。结合案例写一下我的理解,大家看对不对。
案例一:
用工具跑test coverage,发现有些代码没有被覆盖。应该加测试用例吗?我的想法是
,只要测试用例已经覆盖了所有接口文档承诺的功能,就不应该加测试用例。这些代码
可能只是对一些undefined行为的处理。
案例二:
有一个函数:Obj::Plus(Obj rhs),实现了Obj对象的加法,并且针对lhs和rhs不同的
取值情况,有NxN个测试。
现在加一个函数方便使用:
Obj::PlusOne() {
Plus(Obj(1));
}
对于PlusOne,如何写测试程序?如果独立看PlusOne,应该也有N个测试,针对不同lhs
。但这样似乎是重复工作,因为PlusOne实际是Plus的特殊情况。我的想法是,在接口
文档里标明PlusOne是特殊情况,甚至直接放到.h里。然后写少数几个例子即可。
c********n
发帖数: 1065
27
来自主题: Programming版 - 请问matlab的class
发现matlab的class如果要通过method改变自身的properties需要写 obj = obj.method
请问能不能有方法只打 obj.method就可以改变obj的properties呢?
这个要多写个obj = 太烦了
b******7
发帖数: 8200
28
我再补充下,挖个坟,最近在看老印牛人写的代码。。。我有点不喜欢这样的风格。
1313 for (obj = drrfo->drr_firstobj;
1314 err == 0 && obj < drrfo->drr_firstobj + drrfo->drr_numobjs;
1315 err = dmu_object_next(os, &obj, FALSE, 0)) {
1316
1317 if (dmu_object_info(os, obj, NULL) != 0)
1318 continue;
1319
1320 err = dmu_free_object(os, obj);
1321 if (err)
1322 return (err);
1323 }
你们看看这个err,开始是dmu_free_obje... 阅读全帖
d**e
发帖数: 6098
29
来自主题: JobHunting版 - 问个java List的问题
大致上,如果要override Object.equals函数,可以是
public boolean equals(Object obj) {
if(this == obj) {
return true;
}
if(!(obj instanceof Foo)) {
return false;
}
Foo other = (Foo) obj;
boolean result = this.number == other.number;
if(!result) {
return false;
} else {
if(this.name != null) {
result = this.name.equals(other.name);
} else {
result = (other.name == null);
}
if(!result) {
return false;
... 阅读全帖
m*****n
发帖数: 204
30
来自主题: JobHunting版 - LinkedIn 面试题讨论
I wrote a java solution in another thread using iterator-ized (tail)
recursion:
http://www.mitbbs.com/article0/JobHunting/32585567_0.html
It is equivalent to the following python code:
def iterate(list):
for obj in list:
if isinstance(obj, int):
yield obj
else:
for sub_obj in iterate(obj):
yield sub_obj
def main():
list = [ 1, 2, [], 3, [ 4, 5 ], 6 ]
for i in iterate(list):
print i
print 'Done'
r*g
发帖数: 186
31

yes you are right,
I tried your idea and it's much faster than before.
int calcHash(std::vector &v)
{
int res = 0;
for(auto ele: v){
res = res * 2 + ele;
}
return res;
}
bool canIWin(int, int sum, std::vector &v, int obj,
std::unordered_map &cache)
{
int key = calcHash(v);
if(cache.find(key) != cache.end()){
return cache[key];
}
... 阅读全帖

发帖数: 1
32
来自主题: JobHunting版 - 一道Coding面试题目
class Pair {
Pair(String s, String e) {
_1 = s;
_2 = e;
}
public int hashCode() {
return _1.hashCode() | _2.hashCode();
}
public boolean equals(Object obj) {
if (obj == null) return false;
else {
if (obj instanceof Pair) {
Pair pair = (Pair)obj;
return _1.equals(pair._1) && _2.equals(pair._2);
} else {
return false;
}
}
}
String _1;
S... 阅读全帖
g****s
发帖数: 306
33
来自主题: WmGame版 - debug.log
谁知道这三个问题怎么处理,请指教
$ more debug.log
Bad argument 1 to call_other()
Expected: string or array or object Got: 0.
program: adm/obj/simul_efun.c, object: adm/obj/simul_efun, file: /adm/simul_efun
/message.c:8
' timecross' in 'd/sandland/mogaoku.c' (' d/sandland/mogaoku') /d/sandland
/mogaoku.c:45
' message_vision' in 'adm/obj/simul_efun.c' (' adm/obj/simul_efun') /adm/simul_
efun/message.c:8
Error in call out.
Bad argument 1 to wizardp()
Expected: object Got: 0.
program: feature/move.c, object:
b*****l
发帖数: 9499
34
来自主题: Thoughts版 - OpenMP 求救。。。
阶段性胜利了:在 .c 下面,makefile 和 omp_set_num_threads 管用,num_threads
不管用。在 .cpp 下面,omp_set_num_threads 和 num_threads 管用,makefile 不管
用(所以只好写了个 bash script)。。。
大家帮我看看我的 makefile 哪里出错了吧。一个叫做 CMakefile,一个叫做
Makefile,code 一样(除了指向的文件名),结果不一样,后者的 g++ 后面多了些空
格,最后少了一堆参数。。。
$ make -f CMakefile
gcc -c -o CTestOMP.o CTestOMP.c -I. -g -O -fopenmp
gcc -o CTestOMP CTestOMP.o -I. -g -O -fopenmp -lm
$ make -f Makefile
g++ -c -o TestOMP.o TestOMP.cpp
g++ -o TestOMP TestOMP.o -I. -g -O -fopenmp -Wall -lm
##############... 阅读全帖
r*******w
发帖数: 121
35
来自主题: Java版 - 继续问土问题
怎样能够得知一个object的class呢?
就是说我有一个object
我要on the fly new 一个deep copy of it...
so i have to call the related constructor...
but I want the implementation quite generic...
i know i can do
if obj instanceof Class1
then new_obj=new Class1(obj)
else if obj instanceof Class2
then new_obj=new Class2(obj)
etc...
any other more elegant solution?
S******1
发帖数: 216
36
/**
* Definition for a point.
* class Point {
* int x;
* int y;
* Point() { x = 0; y = 0; }
* Point(int a, int b) { x = a; y = b; }
* }
*/
public class Solution {

class Line {
boolean vertical = false;
double slop = 0.0;
double intercept = 0.0;

public Line(Point pt1, Point pt2) {
if (pt1.x == pt2.x)
{
vertical = true;
intercept = pt1.x;
}
else
... 阅读全帖
n**********2
发帖数: 214
37
What is stale object in Java? How will you handle it? For example: You have
a Class A as shown below
public class A{
A(){
// code for database connection
}
// code for other method
}
Now,you are trying to create a object A by its constructor. To initialize
constructor it throws some exception to create database connection.
A obj = new A().
obj.amethod() ;
If obj.amethod() ; will be executed successfully or not ?
How will you stop your code not to use obj?
d******e
发帖数: 143
38
来自主题: Programming版 - makefile question
it's GNU make3.8
if there're 3 source files in 3 sub dir:(current dir is /proj)
/proj/A/a.c
/proj/B/b.c
/proj/C/c.c
/proj/obj
makefile in /proj:
################
DIR1 = ./A
DIR2 = ./B
DIR3 = ./C
OBJDIR = ./obj
VPATH=.:$(DIR1):$(DIR2):$(DIR3):$(OBJDIR)
#default target, link all objs to exe
test: a.o b.o c.o
g++ $^ -o $@
# compile cpp and put objs in OBJDIR
%.o : %.cpp
g++ -c $^ -o $(OBJDIR)/$@
################
problem:
first time run: make test, all 3 object files are created and save
c*********n
发帖数: 128
39
来自主题: Programming版 - 请问vector
It means you can define vector, in which obj could be various types.
E.g. vector is a vector of int, while vector is a vector of
chicks.
However, for a particular vector you defined, all the elements have to
be of type obj, i.e. vector only holds chicks.
r****t
发帖数: 10904
40
来自主题: Programming版 - python gc question
R1 and R2 should be big lists, not strings, aren't they?
del obj 只是让 reference count minus 1,if reference count == 0, interpreter
will get around to call obj.__del__() and destroy the object. Even after the
obj is destroyed, 虽然它不存在了,但是它占的内存也不一定还给 OS 了。
big string obj > 256k uses malloc,这些内存 python interpreter 私藏起来 in case it will need that space again, instead of giving back to OS. This is not leak, because a next big string can reuse this memory again. Python interpreter keep space for 80 delet
l***e
发帖数: 480
41
来自主题: Programming版 - 继续请教C++重载问题,>>
搞定了,多谢。
能不能自己定义分隔符,然后,直接
stream>>obj.a>>obj.b>>obj.c>>obj.d>>ws;
return stream;
?
r****t
发帖数: 10904
42
来自主题: Programming版 - python 可以给class动态添加method吗?
这个不能完全算 dynamic, 毕竟 definition class 的时候就必须 define method 了。如果
只是对实例动态加 method,用
obj.methodname = Types.MethodType(method, obj, obj.__class__)
这个可以用在在 obj 定义以后。 对 class 就直接加。
r******9
发帖数: 129
43
来自主题: Programming版 - copy constructor 问题
关于什么时候调用copy constructor的问题, 看下面的例子
class cType
{
public:
cType(){}
cType(const cType& obj)
{
cout << "copy constructor is called" << endl;
}

cType namedObj()
{
cType d;
return d;
}
cType pointer()
{
cType *d = new cType();
return *d;
}
};
int main()
{
cType obj;
obj.namedObj(); //这个就不会调用copy constructor
obj.pointer(); //这个就会调用 copy constructor
}
为什么会有这个区别呢? 不是说只要返回值不是reference 就会copy么?
多谢指教
p**o
发帖数: 3409
44
来自主题: Programming版 - 简易计算器优先计算级别怎么算?

Alternatively, you can build your own parse tree from ground up. E.g. (
assuming fully parenthesized),
class BinTree (object):
def __init__ (self, root=None, left=None, right=None):
self.root = root
self.left = left
self.right = right
def insert_left (self, obj=None):
self.left = BinTree(obj, left=self.left)
return self.left
def insert_right (self, obj=None):
self.right = BinTree(obj, right=self.right)
return self.right
def tok... 阅读全帖
a*****e
发帖数: 1700
45
来自主题: Programming版 - 1st class citizen
clojure 是 lisp 系,当然到处用括号,很稀奇吗?
你第一种写法,最常见的无非是三个都是同一 obj 的成员函数,没参数,返回修改过
的 obj。但是也可以是返回全新的 obj,也可以是分属三个 class,分别返回下一个
class 的 obj。你不把类型写出来,怎么比较?
d****n
发帖数: 1637
46
来自主题: Programming版 - 1st class citizen
obj
.setX()
.setY()
.setZ()
.error(function(exception){
/*so far a consistent way to catch all exceptions*/
/*if x y z throws same pattern/type exceptions*/
})
//or catch here
catch(e){
switch e {
case X: //
case Y: //
case X: //
}
}
那么问题来了,1 这样写累不累?2 debug break point 往哪行放?
对比平民写法
obj.setX()
catch (e){ /*this shall be exception X, otherwise, die*/}
obj.setY()
catch (e){ /*this shall be exception Y, otherwise, die*/}
obj.setZ()
catch (e){ /*this shall be except... 阅读全帖
d****i
发帖数: 4809
47
来自主题: Programming版 - 有没有人用过org.json.JSONObject?
你没有理解这些annotation的真正用法,应该是返回一个Java object或者Response。
org.json.JSONObject已经是json了,不用像你这样包装成json。应该写成
@GET
@Path("/getJson1")
@Produces(MediaType.APPLICATION_JSON)
public MyObject getJSON1() {
MyObject obj = new MyObject();
obj.setInput("This is input");
obj.setOutput("This is output");
return obj
}
然后定义MyObject class:
public class MyObject {
private String input;
private String output;
// setters and getters
......
}
p********n
发帖数: 273
48
来自主题: Computation版 - How to get the coefficient of the 2D guassian
Hi experts,
I got the fitting result of the gmdistribution object. Now I want to know
the exact expression of the 2D guassian function. From Wikipedia, I know the
expression is
f(x,y) = A*exp(-(a*(x-x0)^2 + 2*b*(x-x0)(y-y0) + c*(y-y0)^2))
where A is the hight of the peak and (x0,y0) is the center of the blob.
As far as I know,
x0 = obj.mu(1)
y0 = obj.mu(2)
My question is how to get coefficients a b c from obj.Sigma?
I supposed obj.Sigma = [a b
b c]
but that was n
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)