由买买提看人间百态

topics

全部话题 - 话题: foo
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
c*****n
发帖数: 95
1
来自主题: JobHunting版 - dropbox 要求真高啊
国人面试。一道dropbox 的高频题
Find files that have the exact same contents in a given directory. Write a
function that takes a path and returns a list of lists or sets. Each set
should contain files that have the same content.
An example output is for the input "/foo/" is:
[
["/foo/bar.png", "/foo/images/foo.png"],
["/foo/file.tmp", "/foo/other.temp", "/foo/temp/baz/that.foo"],
["/foo/1"]
]
顺利写出主要的逻辑,一些API细节没有时间实现。
recruiter 说还要screening 一轮。要不就是国人大哥没有给好评,要不就是这家要求
的确高
z****e
发帖数: 2024
2
来自主题: Programming版 - 大侠们救命, C++ operator new 问题
代码如下:
#include
using namespace std;
class Foo{
public:
Foo(){cout<<"ctr"< void* operator new(size_t){
return pool;
}
private:
static char pool[ ];
};
char Foo::pool[sizeof(Foo)];
void* rbv(){
static char pool[sizeof(Foo)];
return pool;
}
int main(int argc, char* argv[]){
Foo *x=new Foo;//正确,输出 “ctr”
Foo *y=rbv();//错误:invalid conversion from ‘void*’ to ‘Foo*’
}
我就奇怪了,一样是返回一块内存,怎么必须是operator new()返回的就行?而一般
global函数返回的就不行呢?
t****t
发帖数: 6806
3
来自主题: Programming版 - 大侠们救命, C++ operator new 问题
(new Foo) is not equivalent to (Foo::operator new).
new Foo will do following:
call Foo::operator new(sizeof(Foo)). if not found, call ::operator new(
sizeof(Foo)). [5.3.4, 8]
then call Foo::Foo() for the allocated space.[5.3.4, 15].
then returns Foo*.

方?
h*******u
发帖数: 15326
4
来自主题: Programming版 - 看道c++题: brianbench
g++ 3.4.4
FooBar2 f;
Foo& foo=static_cast(f);
通过
Foo& foo=static_cast(FooBar2());
通不过
const Foo& foo=static_cast(FooBar2());
通过
谁给讲讲第二个为什么通不过?
a****m
发帖数: 693
5
#include
#include
#include
using namespace std;
// this function removes trailing spaces from x
void trim (char *str, int size )
{
int i;

/* remove the null terminator */
for ( i = size; i >0; i=i-1 )
{
if ( str[i] == '\n' || str[i]=='\t' || str[i]==' ' )
{
str[i-1] = '\0';
/* we're done, so just exit the function by returning */
return;
}
}
/* if we get all the way to her... 阅读全帖
t**********s
发帖数: 930
6
只找到了一个 catalina.properties:
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unles... 阅读全帖
e*******s
发帖数: 1979
7
以下这段代码 把set的iterator直接传递到parameter为reference的函数里
报错
test.cpp: In function 'int main()':
test.cpp:110: error: invalid initialization of reference of type 'std::
string&' from expression of type 'const std::basic_string traits, std::allocator >'
test.cpp:67: error: in passing argument 1 of 'void foo(std::string&)'
make: *** [a] Error 1
如果修改代码
1. void foo(string &s) --> void foo(string s)
2. string s = *it; foo(s);
3. void foo(string &s) --> void foo(cons... 阅读全帖
c*****n
发帖数: 123
8
给一个file path,把里面所有相同的文件都放到一起,把路径用List>
输出出来。
相同的定义式byte对比。
相同文件的文件名不一定一样,里面可能还会有sub folder
# Question:
#
# Find files that have the exact same contents in a given directory. Write a
function that takes a path and returns a list of lists or sets. Each set
should contain files that have the same content.
#
# An example output is for the input "/foo/" is:
# [
# ["/foo/bar.png", "/foo/images/foo.png"],
# ["/foo/file.tmp", "/foo/other.temp", "/foo/temp/baz/that.foo"]
# ]
#
求大牛前辈们指... 阅读全帖
n******1
发帖数: 3756
9
来自主题: Java版 - 问个autoboxing的问题
有两个demo,这里的参数匹配有什么原则,有什么地方写的比较清楚,好像不仅是
autoboxing的问题
//output int 1
public class Demo1{
public static void main(String []args){
short a = 1;
Demo1 demo = new Demo1();
demo.foo(a);
}

void foo(Short x){
System.out.println("Short"+x);
}
void foo(int x){
System.out.println("int"+x);
}
void foo(Integer x){
System.out.println("Integer"+x);
}

}
//output short 1
public class Demo2{
public static void... 阅读全帖
l**********n
发帖数: 8443
10
来自主题: Java版 - Java 问题
@Test
public void testAssign(){
class Foo{
private String bar;
public String getBar() {
return bar;
}
public void setBar(String bar) {
this.bar = bar;
}
}
Foo foo = new Foo();
foo.setBar("foobar");
// foo.getBar() = "foobarfoo"; IDE will complain lacking lvalue
String s = foo.getBar();
s = "foobarfoo";
Assert.assertTrue(!s.equals... 阅读全帖
I****k
发帖数: 35
11
来自主题: Programming版 - 经典C++问题求助
Given the class definition as follows, what the output of B objB ?
class A{
public: A(){this->foo();}
virtual void foo()=0 {cout<<"A::Foo()"< };
class B : public A{
public: B(){this->foo();}
virtual void foo(){cout<<"B::Foo()"< };
The output should be
A::Foo()
B::Foo()
原因是不是因为this只能表示当前的对象?还是因为vtable在ctor的时候还没有建立起
来?多谢了,我的概念不是很清楚。。。
N***r
发帖数: 2539
12
来自主题: Programming版 - c++ 宏的问题
有这么一段代码
template
void foo(SomeKindofClass & myClass);
函数foo的具体实现分布在各个C文件中,比如在myProblemClassABC中
templet <>
void
foo(SomeKindofClass & myClass)
{
/* real codes here */
}
在myProblemClassXYZ中
templet <>
void
foo(SomeKindofClass & myClass)
{
/* real codes here */
}
现在有另一个function,功能是根据从输入文件中读到的myProblemClassXXX来调用foo
,很笨的方法就是这样
void function(std::vector class_names_from_input)
{
SomeKindofClass myClass = SomeKindofClass(... 阅读全帖
L***s
发帖数: 1148
13
来自主题: Programming版 - python一问,怎么实现这个函数

需求提得有问题,会写程序的人一般不这么问
我猜你可能想要下面的效果,猜得不对你自己酌情修改
In [4]: class Foo (object):
...:
...: def __init__ (self, raw_dict):
...: self.num_to_string_set = {}
...: for tup, string in raw_dict.iteritems():
...: for num in tup:
...: self.num_to_string_set\
...: .setdefault(num,set())\
...: .add(string)
...:
...: def query (self, *nums):
...: assert len(nums) > 0
...: ... 阅读全帖
G***l
发帖数: 355
14
来自主题: Programming版 - 这二个在C++中有区别不?
那要Foo实现了move constructor。即便如此,那也是move了new Foo里面的东西,那个
new Foo本身还是leak了。
从java过来的用c++,最应该注意的是c++有value semantics。
除了基本类型,java里只有Foo f = new Foo();
c++有Foo* f = new Foo();和Foo f;而且后者更常用。
m*********a
发帖数: 3299
15
来自主题: Programming版 - 这二个在C++中有区别不?
这个就是很不规则的
Foo *myFoo=new Foo();的话C++,如果出了code block{}的话,
myFoo会call Foo()但是不会call ~Foo();需要自己call ~Foo()不?
但是Foo myFoo;的话C++,如果出了code block{}的话,
myFoo会call Foo()和 ~Foo();
不知是为啥,大牛解释一下。
Java是咋靠destructor的?
G***l
发帖数: 355
16
来自主题: Programming版 - 这二个在C++中有区别不?
那要Foo实现了move constructor。即便如此,那也是move了new Foo里面的东西,那个
new Foo本身还是leak了。
从java过来的用c++,最应该注意的是c++有value semantics。
除了基本类型,java里只有Foo f = new Foo();
c++有Foo* f = new Foo();和Foo f;而且后者更常用。
m*********a
发帖数: 3299
17
来自主题: Programming版 - 这二个在C++中有区别不?
这个就是很不规则的
Foo *myFoo=new Foo();的话C++,如果出了code block{}的话,
myFoo会call Foo()但是不会call ~Foo();需要自己call ~Foo()不?
但是Foo myFoo;的话C++,如果出了code block{}的话,
myFoo会call Foo()和 ~Foo();
不知是为啥,大牛解释一下。
Java是咋靠destructor的?
e*******s
发帖数: 1979
18
以下这段代码 把set的iterator直接传递到parameter为reference的函数里
报错
test.cpp: In function 'int main()':
test.cpp:110: error: invalid initialization of reference of type 'std::
string&' from expression of type 'const std::basic_string traits, std::allocator >'
test.cpp:67: error: in passing argument 1 of 'void foo(std::string&)'
make: *** [a] Error 1
如果修改代码
1. void foo(string &s) --> void foo(string s)
2. string s = *it; foo(s);
3. void foo(string &s) --> void foo(cons... 阅读全帖
N********n
发帖数: 8363
19
来自主题: Programming版 - node.js快,到底什么是根本的原因?

语言是工具不是花瓶,是拿来干活用的不是当摆设看怎么美观的。任何语言
都有表达能力,静态语言的表达问题时出错比动态少,所以做工程方便。一
个class Foo定义一个变量a, 如果代码写成foo.b,IDE马上报错Foo没有定
义b,有错立刻改,这个就是做工程趁手的好语言。
换JS就不行了,Foo的定义动态可变。没准哪来个prototype就加个b进去,
IDE无法知道你这程序动态咋执行的,所以干脆不纠错,你爱写啥写啥,
foo.c, foo.d, foo.whatever随你便。谁知道Foo到底咋定义的。为了动态
导致IDE爱莫能助是典型的捡芝麻丢西瓜,说明JS设计者分不清主次。
o***s
发帖数: 42149
20
阿黛尔大赢
蕾哈娜尺度大胆
现场放惠特尼休斯顿照片
Taylor Swift气场从容
北京时间2月13日消息,据国外媒体报道,2012年度第54届格莱美音乐节的颁奖典礼12日晚在美国洛杉矶举行,英国女歌手阿黛尔(Adele)在她拿到提名的六个奖项中全部获胜,一共捧得包括“年度制作”和“年度最佳专辑”在内的六项大奖,不仅成为了本届格莱美的最大赢家,还追平了碧昂斯(Beyonce)两年前创下的单届格莱美女歌手夺奖最多的纪录。在阿黛尔之后,Foo Fighters乐队也拿到了五项大奖,同样成绩不俗。
天后一天前去世 颁奖礼被悲伤笼罩
美国当地时间2月11日下午,美国流行天后惠特尼-休斯顿(Whitney Houston)突然去世,年仅48岁。由于她在颁奖礼举行一天前的突然离开,这次格莱美的颁奖礼无疑受到了很大的影响,格莱美主办方临时为她准备了致敬的环节。为今天格莱美颁奖礼担任开场嘉宾的是摇滚老将布鲁斯-斯普林斯汀(Bruce Springsteen),他演唱了自己的新歌《We Take Care of Our Own》。在斯普林斯汀的简短的开场表演之后,格莱美近七年以来的第一位正式主持人、说... 阅读全帖
n******n
发帖数: 49
21
来自主题: JobHunting版 - 攒人品 报BB面经
昨天早晨电面BB,no luck.
主要是对印度人的口音还是有些不习惯,而且不明原因昨天有一段时间电话背景噪音非
常大,非常影响面试。
题目如下:
1. 打印Hello World字符串。这题看起来简单,但是如果概念不清,很容易弄错或者绕
很久。
回忆了一下,回头又编了一次,代码应该是
void foo(char** a){
*a = "hello world";
}
int main(){
char* c;
foo(&c);
printf("%s",c);
return 0;
}
这题的trap就在char* c之后,只是声明了c但并没有定义c。如果用debugger trace,就
会发现&c = 0x0012ff40但是c是一个bad pointer,即里面是garbage value, 这时候如
果直接用foo(c),编译器会提示错误: the variable "c" can't be used without
definition. 这和下面这段程序是一个道理:
void bar(int a){
cout << a << end... 阅读全帖
c*****e
发帖数: 737
22
来自主题: JobHunting版 - 微软C++面试题
1 #include
2
3 class A
4 {
5 public:
6 A(int v_) : v(v_) {};
7 virtual void foo() {std::cout << "A:" << v << "\n";}
8 int v;
9 };
10
11 class B : public A
12 {
13 public:
14 B(int w_, int z_):w(w_), A(z_){};
15 virtual void foo() {std::cout << "B:" << w << "\n";}
16 int w;
17 };
18
19 class C : public A
20 {
21 public:
22 C(int k): A(k){};
23 v... 阅读全帖
c*****e
发帖数: 737
23
来自主题: JobHunting版 - 微软C++面试题
1 #include
2
3 class A
4 {
5 public:
6 A(int v_) : v(v_) {};
7 virtual void foo() {std::cout << "A:" << v << "\n";}
8 int v;
9 };
10
11 class B : public A
12 {
13 public:
14 B(int w_, int z_):w(w_), A(z_){};
15 virtual void foo() {std::cout << "B:" << w << "\n";}
16 int w;
17 };
18
19 class C : public A
20 {
21 public:
22 C(int k): A(k){};
23 v... 阅读全帖
d**********n
发帖数: 2031
24
来自主题: Joke版 - 攒人品 报BB面经 (转载)
【 以下文字转载自 JobHunting 讨论区 】
发信人: nancylin (nancylin), 信区: JobHunting
标 题: 攒人品 报BB面经
关键字: phone interview Bloomberg
发信站: BBS 未名空间站 (Thu Oct 28 15:47:29 2010, 美东)
昨天早晨电面BB,no luck.
主要是对印度人的口音还是有些不习惯,而且不明原因昨天有一段时间电话背景噪音非
常大,非常影响面试。
题目如下:
1. 打印Hello World字符串。这题看起来简单,但是如果概念不清,很容易弄错或者绕
很久。
回忆了一下,回头又编了一次,代码应该是
void foo(char** a){
*a = "hello world";
}
int main(){
char* c;
foo(&c);
printf("%s",c);
return 0;
}
这题的trap就在char* c之后,只是声明了c但并没有定义c。如果用debugger trace,就
会发现&c = 0x0012ff40但是c是... 阅读全帖
l**n
发帖数: 7272
25
来自主题: Apple版 - Unix的缺陷(ZT)
虽然这里的码工比较少,但是能appreciate coding和programming的朋友也可以看看。
我觉得挺有意思的。
http://blog.sina.com.cn/s/blog_5d90e82f01014k5j.html
我想通过这篇文章解释一下我对 Unix 哲学本质的理解。我虽然指出 Unix 的一个设计
问题,但目的并不是打击人们对 Unix 的兴趣。虽然 Unix 在基础概念上有一个挺严重
的问题,但是经过多年的发展之后,这个问题恐怕已经被各种别的因素所弥补(比如大
量的人力)。但是如果开始正视这个问题,我们也许就可以缓慢的改善系统的结构,从
而使得它用起来更加高效,方便和安全,那又未尝不可。同时也希望这里对 Unix 命令
本质的阐述能帮助人迅速的掌握 Unix,灵活的应用它的潜力,避免它的缺点。
通常所说的“Unix哲学”包括以下三条原则[Mcllroy]:
一个程序只做一件事情,并且把它做好。
程序之间能够协同工作。
程序处理文本流,因为它是一个通用的接口。
这三条原则当中,前两条其实早于 Unix 就已经存在,它们描述的其实是程序设计最... 阅读全帖
m***c
发帖数: 257
26
求一个C和C++精通的同学,有个小程序要写,对你们可能很简单,主要是急用,12个小
时内写完,估计可能要写300行左右的代码,100个包子酬谢。
时间改为一周。从今天(3/6/2013)开始算吧。
对Hindley-Milner type checking熟悉的同学发私信吧。感兴趣的话我发给你详细的说
明。
Basically, you will implement a type-checking algorithm based on the
language described。For example,
Input
int foo
int bar
double x
double y
string z
bool success
int[7] a
int[7] b
int[15] c
double[15] d
string[7] note
x = y
foo = b[2] + bar
foo = y * bar
z = z - foo
y = d[4] * x / foo
success = foo + a[1] <= c[7]
note[2] = x - d[3] * randy
no... 阅读全帖
g*********s
发帖数: 1782
27
来自主题: Programming版 - 关于构造函数的一道测试题 (转载)
【 以下文字转载自 JobHunting 讨论区 】
发信人: gandjmitbbs (Nothing), 信区: JobHunting
标 题: 关于构造函数的一道测试题
发信站: BBS 未名空间站 (Sun Dec 16 02:42:51 2007)
class Foo{
public:
//Foo(){}
Foo(int i){}
};
class Bar: Foo {
public:
Bar(){}
};
Bar objBar;
问编译是否能通过?如果不能如何修正?
自己试了一下,说没有合适的Foo默认构造函数可用。将那行注释关掉就行了。但是编
译器不是应该自动生成一个Foo::Foo(){}吗?
i**p
发帖数: 902
28
来自主题: Programming版 - Clearcase 的一点疑问
foo.cpp 有两个版本, 后面是check-in时间
foo.cpp@/main/1 7/2/2009
foo.cpp@/main/2 7/3/2009
7/4 用下面的规则编译, 产生的目标码新于foo.cpp@/main/2
element foo.cpp /main/1
然后将规则改作如下
element foo.cpp /main/2
请问再编译的时候foo.cpp@/main/2会被重新编译吗?如果是的话,道理何在?
t****t
发帖数: 6806
29
来自主题: Programming版 - 问问C++的diamond problem
first, if both B and C override a virtual function foo(), but D did not, the
program is ill-formed anyway. so if both B and C override foo(), D must
also override foo().
Using foo(), this->foo(), or ((A*)this)->foo() are all equivalent since this
always points to an object D, with final overrider D::foo(). so your method
is wrong.
h****8
发帖数: 599
30
来自主题: Programming版 - 看道c++题: brianbench
有没有可能是因为Foo &foo = static_cast(FooBar2 f) 中的f在cast完以后就
生命结束了,这样foo是一个无效地址的引用,所以不可以
而FooBar2 f;
Foo &foo = static_cast(f);
中f还是有效的,所以编译通过了
d****p
发帖数: 685
31
来自主题: Programming版 - 看道c++题: brianbench
OK, could you tell if the following code is OK? What's the value of a in
main()?
class Foo
{
public:
....Foo(int a) : a(a) {}
....int GetValue() { return a; }
private:
....int a;
};
int main()
{
....const Foo& foo = static_cast(Foo(1));
... int a = foo.GetValue();
....return 0;
}

is
a
do
X****r
发帖数: 3557
32
来自主题: Programming版 - question about mock
单元测试是一个很好的习惯,我的看法是凡是对最终产品有贡献的代码
都必须有单元测试。被测试的单元应该有着尽可能清晰的界面,你最终
会发现这样的设计会导致更灵活的代码,即使不是为了测试而是将来的
代码重构也是有利的。
你这里的情况有两种可能的解决方向。如果foo这个函数和X的其他成员
耦合程度很高的话,你可以着重于测试foo所提供的功能,就像实际的
使用者一样来使用foo,包括调用X的其他函数(它们本身也被其他单元
测试所覆盖),从而确定foo的正确性。比如:
void XTest::testFoo() {
X x;
// setup x here.
x.foo();
// assert the state of x here.
}
另一方面,如果foo这个函数本身相对独立的话,你可以把它的实现作
为一个不依赖于X的其他成员的函数分出来,这样这个实现函数就可以
被单独测试:
class X {
public:
void foo() { fooImpl(abc_, p); }
private:
ABC abc_;
Node * p;
void
z***9
发帖数: 696
33
来自主题: Programming版 - Interview question: is the following code OK?
is boost::shared_ptr a smart pointer?
{
Foo_ptr foo(new Foo(id));
fooMap[id] = foo;
return foo;
}
the foo object deletes itself at the end of the static function, which will
cause the memory (pointed bt new Foo(id)) to be released too. however, the
function will assign a copy of the foo object to fooMap[id] and return a copy of the same object too , both of which contais that pointer (but the memory is no longer available).
edit: guess boost::shared_ptr implements the reference counting, s
h********8
发帖数: 7355
34
C里,得自己declare 一个global mythis pointer指向global foo。
#include
int foo = 100;
int * mythis=&foo;
int bar()
{
int foo;
/* local foo = global foo, how to implemented? */
foo=*mythis;
return 0;
}
r****c
发帖数: 1494
35
来自主题: Programming版 - 最讨厌的人是。。。
http://www.faqs.org/docs/artu/ten-thousand.html
Master Foo and the Ten Thousand Lines
Master Foo once said to a visiting programmer: “There is more Unix-nature
in one line of shell script than there is in ten thousand lines of C.”
The programmer, who was very proud of his mastery of C, said: “How can this
be? C is the language in which the very kernel of Unix is implemented!”
Master Foo replied: “That is so. Nevertheless, there is more Unix-nature in
one line of shell script than there is in ten... 阅读全帖
q****x
发帖数: 7404
36
来自主题: Programming版 - 几个C++书写风格疑问
都是关于书写风格的。
1. 有必要手动禁用default ctor吗?
class A {
public:
explicit A(int i) : data_(i) {}
private:
int data_;
};
class A {
public:
explicit A(int i) : data_(i) {}
A() = delete;
private:
int data_;
};
有人认为第一个写法就够了,编译器不会自动生成default ctor。有人认为第二个写法
好,直接告诉用户default ctor是要禁用的,以免用户不小心又添加了default ctor。
谁有道理?
2. 纯虚类的虚函数声明。
纯虚类里只要有一个函数为虚,则所有都为虚。但声明纯虚时可以有多个变种如下。哪
个规范?
第一个写法,把所有的虚函数都声明为纯虚。
class A {
public:
virtual ~A() = 0;
virtual void foo() = 0;
virtual void bar() = 0;
};
inline A::~A() = d... 阅读全帖
m*********a
发帖数: 3299
37
来自主题: Programming版 - 请教C++11的rvalue ref
如果有MyClass
foo(MyClass())就会调用foo(MyClass&&)
MyClass()产生一个新的unamed object
如果先定义一个
MyClass myClass;
foo(myClass)就是调用foo(MyClass&)或者foo(const MyClass &)
foo(MyClass&)和foo(const MyClass &)虽然signature 不同
但是不能overload.
虽然const这儿是low level modifier, 但是const low level可以接受nonconst 和
const的variable
c*****e
发帖数: 3226
38
来自主题: Programming版 - 最近学了一下 Go
func (*xyx) foo(m *abc)
var x1 xyz
var x2 *xyz
x1.foo OK
x2.foo. OK
var a1 abc
var a2 *abc
x1.foo(a2) OK
x1.foo(a1) not OK
再加上 interface 你就更晕。然后又是 new , make, 这不是操他妈的 有病么。 还
不如学 java, 就一个 Foo f = new Foo(...)
何必区分这些指针的细节呢。
就一个画虎画成猫的写照。 典型的一个c/c++ 怪胎。
c*****t
发帖数: 1879
39
来自主题: Programming版 - 珍惜生命,远离 R 和 Go
最近无聊,稍微研究了下两个语言,彻底被惊呆了。
第一是 R 。可以说是世界上最 fucked up 的语言之一(COBOL 是另外一个)。
你看一下这篇文章就明白了:
https://xianblog.wordpress.com/2010/09/13/simply-start-over-and-build-
something-
better/
第二就是 Go 。整个一傻逼语言。
1) 如果该语言有 pointer,但是其速度比 Java 还慢点,谁 TMD 有毛病才用它。
再不用说,Go 里面需要知道很多很多 low level 的东西,但是搞了半天比 Java
还慢?!!
2) Stupid copies 。好吧,你有 pointer 不用,非得 pass by value (i.e.
struct copy),真是脑袋抽筋了。copy 大部分情况下比 reference 慢。
reference 是可以放在 register 里的,而 struct 一旦比 register 大,
就会占内存。然后 Go idiots 说 cache 很 precious,那你还搞那么多 copy... 阅读全帖
d****n
发帖数: 1637
40
来自主题: Programming版 - go 的坑(转载)
献给gopher们,俺还没踩到,不过惊出一身冷汗。希望对其他gopher有用
http://studygolang.com/articles/5188
坑(s)
每种编程语言都有自己的专属坑(s),Go虽出身名门,但毕竟年轻,坑也不少,在error
处理这块也可以列出几个。
1、 Go FAQ:Why is my nil error value not equal to nil?
type MyError string
func (e *MyError) Error() string {
return string(*e)
}
var ErrBad = MyError("ErrBad")
func bad() bool {
return false
}
func returnsError() error {
var p *MyError = nil
if bad() {
p = &ErrBad
}
return p // Will always return a non-nil error.
}
func main() {... 阅读全帖
A*******e
发帖数: 2419
41
来自主题: Programming版 - 问个C++ type alias的问题
下面两种写法,定义Alias的位置语义上有区别吗?Alias都只是foo.cc里可见吧?
foo.cc
using Alias = namespace_x::Alias
namespace foo {
namespace {
// some code using Alias
} // namespace
// some other code using Alias
} // namespace foo
vs
foo.cc
namespace foo {
namespace {
using Alias = namespace_x::Alias
// some code using Alias
} // namespace
// some other code using Alias
} // namespace foo
t********e
发帖数: 1169
42
【 以下文字转载自 JobHunting 讨论区 】
发信人: mitbbs59 (bEQi), 信区: JobHunting
标 题: 本版1年以内的所有 面经题目,含帖子link [为大家方便]
发信站: BBS 未名空间站 (Fri Jan 29 14:20:44 2010, 美东)
不敢保证全部涵盖,大部分的都在。
我自己找了一遍,大家一起用着都方便。
不过只是含有题目的帖子 我才包含进来了,只分享经验没贴题目的 我都没有包含
进来。
大家复习着方便。
1. 一个sorted interger Array[1...N], 已知范围 1...N+1. 已知一个数字missing。
找该数字。
把原题改为unsorted,找missing数字。 performance。
2. 复制linked list。 已知每个节点有两个pointer,一个指向后一个节点,另一个指向
其他任意一节点。 O(n)时间内,无附加内存,复制该linked list。(存储不连续)
3. 一个party N个人,如果一个人不认识任何其他人,又被任何其他人认识,此人为
celeb... 阅读全帖
t********e
发帖数: 1169
43
【 以下文字转载自 JobHunting 讨论区 】
发信人: mitbbs59 (bEQi), 信区: JobHunting
标 题: 本版1年以内的所有 面经题目,含帖子link [为大家方便]
发信站: BBS 未名空间站 (Fri Jan 29 14:20:44 2010, 美东)
不敢保证全部涵盖,大部分的都在。
我自己找了一遍,大家一起用着都方便。
不过只是含有题目的帖子 我才包含进来了,只分享经验没贴题目的 我都没有包含
进来。
大家复习着方便。
1. 一个sorted interger Array[1...N], 已知范围 1...N+1. 已知一个数字missing。
找该数字。
把原题改为unsorted,找missing数字。 performance。
2. 复制linked list。 已知每个节点有两个pointer,一个指向后一个节点,另一个指向
其他任意一节点。 O(n)时间内,无附加内存,复制该linked list。(存储不连续)
3. 一个party N个人,如果一个人不认识任何其他人,又被任何其他人认识,此人为
celeb... 阅读全帖
q**p
发帖数: 147
44
来自主题: JobHunting版 - 问两个题
1,
void newBuffer(char* outBuffer, size_t sz) {
outBuffer = new char[sz];
}
int main() {
const char* kung = "KUNG";
char* foo;
size_t len = strlen(kung);
newBuffer(foo, len);
memset(foo, 0, len+1);
strncpy(foo, kung, len);
cout << foo << endl;
}
这个可以编译,但是有bug,运行之后知道是foo的问题,具体不太明白,求指点
2,
B is a class inherited from A.
B *myPointer = new B();
A *myOtherPointer = myPointer;
printf(“%x”, myPointer);
printf(“%x”, myOtherPointer);
这段代码的两个... 阅读全帖
l****p
发帖数: 397
45
来自主题: JobHunting版 - Twitter实习第二轮电面总结
面试官从口音可以听出来是个阿三哥。
一开始先问我的学历,然后问我熟悉哪些编程语言和技术。然后开始写程序。
面试官写了一小段程序:
class A
def foo
puts "hello"
end
end
class B < A
def foo
puts "world"
end
end
s = B.new
s.foo
然后问我这时打印出什么,我说是"world",然后问我说怎么让s打印出"hello",写代
码实现。我心想这问题也太白痴了吧:
s = A.new
s.foo
然后他说s必须是B的对象。我明白了他要让我调用父类方法,但我一时忘了Ruby怎么调
父类方法了,于是绕开,说Ruby允许重新打开了个类去重定义它的方法:
class B < A
def foo
puts "hello"
end
end
然后他又说如果不要重定义呢。这下没招了,于是把最早的B.foo的定义里写了个super
,说我忘了Ruby怎么调父类了,我可以查一下。他说不用了,这就是他所期望了。(面
试后查了一下,Rub... 阅读全帖
l****p
发帖数: 397
46
来自主题: JobHunting版 - Twitter实习第二轮电面总结
面试官从口音可以听出来是个阿三哥。
一开始先问我的学历,然后问我熟悉哪些编程语言和技术。然后开始写程序。
面试官写了一小段程序:
class A
def foo
puts "hello"
end
end
class B < A
def foo
puts "world"
end
end
s = B.new
s.foo
然后问我这时打印出什么,我说是"world",然后问我说怎么让s打印出"hello",写代
码实现。我心想这问题也太白痴了吧:
s = A.new
s.foo
然后他说s必须是B的对象。我明白了他要让我调用父类方法,但我一时忘了Ruby怎么调
父类方法了,于是绕开,说Ruby允许重新打开了个类去重定义它的方法:
class B < A
def foo
puts "hello"
end
end
然后他又说如果不要重定义呢。这下没招了,于是把最早的B.foo的定义里写了个super
,说我忘了Ruby怎么调父类了,我可以查一下。他说不用了,这就是他所期望了。(面
试后查了一下,Rub... 阅读全帖
d**********x
发帖数: 4083
47
class A {
public:
void foo() {n = 0;}
private:
int n;
};
int main() {
A a;
A* p = new A;
a.foo();
p->foo();
return 0;
}
用gdb调试:
13 a.foo();
6: x/8i 0x400576
0x400576 : mov %rax,-0x18(%rbp)
=> 0x40057a : lea -0x10(%rbp),%rax
0x40057e : mov %rax,%rdi
0x400581 : callq 0x40059a
0x400586 : mov -0x18(%rbp),%rax
0x40058a : ... 阅读全帖
s*i
发帖数: 5025
48
来自主题: JobHunting版 - 求问一道multithreading问题
这个可以吗?
Object b = new Object();
boolean foo = false;
void functionFoo() {
while(1){
synchronized(b) {
if(foo) b.wait();
System.out.print("Foo");
foo = true;
b.notify();
}
}
}
void functionBar() {
while(1) {
synchronized(b) {
if(!foo) b.wait();
System.out.print("Bar");
foo = false;
b.notify()... 阅读全帖
p*****2
发帖数: 21240
49
来自主题: JobHunting版 - 求问一道multithreading问题

想了一下,还是应该用actors
import akka.actor._
case class Foo(times: Int)
case class Bar(times: Int)
case object Foo
case object Bar
class FooActor(barActor: ActorRef) extends Actor {
def receive = {
case Foo(times) if times>0 =>
print(Foo)
barActor ! Bar(times)
}
}
class BarActor() extends Actor {
def receive = {
case Bar(times) =>
println(Bar)
sender ! Foo(times-1)
}
}
object test extends App{
val system = ActorSystem()
val barActor = system.actorOf(Props(new... 阅读全帖
f********a
发帖数: 1109
50
【 以下文字转载自 Programming 讨论区 】
发信人: ozin (ozin), 信区: Programming
标 题: 王银看kotlin(本文建议零售价 ¥15)
发信站: BBS 未名空间站 (Thu May 25 18:06:39 2017, 美东)
Kotlin 和 Checked Exception
最近 JetBrains 的 Kotlin 语言忽然成了热门话题。国内小编们传言说,Kotlin 取代
了 Java,成为了 Android 的“钦定语言”,很多人听了之后热血沸腾。初学者们也开
始注意到 Kotlin,问出各种“傻问题”,很“功利”的问题,比如“现在学 Kotlin
是不是太早了一点?” 结果引起一些 Kotlin 老鸟们的鄙视。当然也有人来信,请求
我评价 Kotlin。
对于这种评价语言的请求,我一般都不予理睬的。作为一个专业的语言研究者,我的职
责不应该是去评价别人设计的语言。然而浏览了 Kotlin 的文档之后,我发现 Kotlin
的设计者误解了一个重要的问题——关于是否需要 checked exception。对于这个话题
我已经思考... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)