#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... 阅读全帖
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... 阅读全帖
谢谢,我有了,不过我在安装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... 阅读全帖
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
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();
}
}
}
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.
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);
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'
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];
}
... 阅读全帖
怎样能够得知一个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?
/**
* 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
... 阅读全帖
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?
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
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.
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
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... 阅读全帖
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