由买买提看人间百态

topics

全部话题 - 话题: baseclass
(共0页)
k****i
发帖数: 1072
1
1. For example:
public class BaseClass
{
public virtual void TraceSelf()
{
Trace.WriteLine("BaseClass");
}
}
public class SubClass:BaseClass
{
public override void TraceSelf()
{
Trace.WriteLine("SubClass");
}
}
BaseClass obj=new SubClass();
obj.TraceSelf(); //What's the output here?
public class BaseClass
{
public virtual void TraceSelf()
{
Trace.WriteLine("BaseClass");
}
}
public class SubClass:BaseClass
{
public new void TraceSelf()
{
Trace.WriteLine("SubClass");
}
}
BaseClass obj=new
P*******e
发帖数: 65
2
If the function inherited from the base template class has paramters as the
type of the base template class, the "this->" can be avoided. Otherwise, "
this->" is necessary to tell the compiler the type used in the base template.
template
class BaseClass {
public:
BaseClass() {};
~BaseClass() {};
void Write(T var);
T Read(void);
private:
T variable;
};
template
class ChildClass : public BaseClass {
public:
ChildClass() {};
~ChildClass() {};
void WriteA
e*****r
发帖数: 700
3
来自主题: Programming版 - Python 如何自动import multiple files
Python 高手请帮忙看看如何实现自动import
我想import的情况如下:
有一些py文件定义了一些class,基本上都是一个class的子class,每个文件末端把那个
class initiate 加到一个list 里
比如:
file a.py:
from baseclass import *

classes=[]
class a(baseclass):
pass
classes.append(a)
file b.py:
from baseclass import *
class b(baseclass):
pass
classes.append(b)
我要实现的目的:
from a import *
from b import *
请问如何自动实现这些import? 这个folder里可能有不确定数量的py module.
谢谢
N******K
发帖数: 10202
4
( in file a.cpp line 21)
shared_ptr sp1(new ClassXXX)
DEBUG_CODE(register(sp1.get(), "ClassXXX", "a.cpp", 21))
...
( in file b.cpp line 11)
shared_ptr sp2(new ClassXX)
DEBUG_CODE(register(sp2.get(), "ClassXX" "b.cpp", 11))
ClassXXX和ClassXX都继承一个基类 BaseClass
register(BaseClass*, std::string, std::string, long)
~BaseClass()
{
DEBUG_CODE(unregister(this);)
}
在main程序结束的时候
print_register_record() 如果这两个类没有被销毁 那么
unregistered class list
ClassXXX in a.cpp ,line 21
ClassXX in b.cpp ,line 11
大家看看 有啥问题么?
r*****r
发帖数: 397
5
来自主题: Programming版 - inheritence problem
I have a strange compiling error, does anybody have this problem before?
There is a base class and an inherit class, very simple,
class BaseClass
{
...
}
class InheritedClass : public BaseClass
{...
}
when i compile,got the error
InheritedClass.h:11: error: expected class-name before ‘{’ token
h*****g
发帖数: 312
6
来自主题: JobHunting版 - C++ online Test 一题
那如果在baseclass 自己写一个default ctr 也应该解决问题了吧?
h*****g
发帖数: 312
7
来自主题: JobHunting版 - C++ 一题
难道是要call baseclass的ctr to cast from Derived* to Base*?
h******e
发帖数: 52
8
来自主题: JobHunting版 - amazon 面经
这里Interface比abstract好,当时考虑的是还有一些可以在baseclass里做,后来没有
想到有那些,也没有时间去改了。 当然这里还有很多要改近的地方。 整个design只有
十分钟时间左右,也不多结果做讨论,我就想知道, 这种考法,面试官想知道什么?
1. OOD基本概念,封装,继承和多态
2. 思考问题的方式,比如怎么样和面试官交流,得到requirement
3. class里面的完整性 - 这个很难如果那个东西你不了解的话。
N********n
发帖数: 8363
9
来自主题: JobHunting版 - uber 的一个面试题

你放个TYPE进去基本上要秒FAIL的。用OO思路,CLASS本身就是TYPE。应该
有个BASE CLASS CELL存通用信息,然后SUBCLASS VALUE CELL和SUBCLASS
FORMULA CELL存特定信息,从BASECLASS继承通用信息。酱紫。
b***i
发帖数: 3043
10
网上有一个从本地用ZipFile读的,但是我要applet,就不知道怎么做了。
那个网页说用JarURLConnection,也用了,具体到了读入就读入了-1,大侠帮帮妈忙?
URL url0 = baseClass.class.getResource(jarFileName);
String ok = "jar:file:"+ url0.getPath()+"!/"+name; // name is file name
inside
URL url=new URL(ok);
JarURLConnection conn = (JarURLConnection)url.openConnection();
ZipEntry ze=(ZipEntry)conn.getJarEntry();
int size=(int)ze.getSize();
InputStream fis= conn.getInputStream();
BufferedInputStream bis=new BufferedInputStream(fis);
ZipInputStream zis=new ZipInpu
d********g
发帖数: 10550
11
来自主题: Linux版 - 请教python问题
这是override constructor,new style的class,super class就是object。没规定一
定要super,如果你不要基类的constructor的话。不光是__init__(),任何method都是
这个道理,要扩展(重用之前的代码)就是super,不super就是直接覆盖
因为object本身是不接收args、kwargs的所以可以这样简写,如果是从别的有可能接受
args的class继承,为了安全一般还得这样写:
class Reader(BaseClass):
def __init__(self, filename=None, *args, **kwargs):
super(Reader, self).__init__(*args, **kwargs)
# 然后再处理你自己的filename
Python 3里可以把super(Reader, self)简化成super()
d********g
发帖数: 10550
12
来自主题: Linux版 - 请教python问题
这是override constructor,new style的class,super class就是object。没规定一
定要super,如果你不要基类的constructor的话。不光是__init__(),任何method都是
这个道理,要扩展(重用之前的代码)就是super,不super就是直接覆盖
因为object本身是不接收args、kwargs的所以可以这样简写,如果是从别的有可能接受
args的class继承,为了安全一般还得这样写:
class Reader(BaseClass):
def __init__(self, filename=None, *args, **kwargs):
super(Reader, self).__init__(*args, **kwargs)
# 然后再处理你自己的filename
Python 3里可以把super(Reader, self)简化成super()
h*****g
发帖数: 312
13
来自主题: Programming版 - C++ online Test 2题
class Base{
public:
Base();
virtual ~Base();
};
class Derived: protected Base{
public:
virtual ~Derived();
};
int _tmain(int argc, _TCHAR* argv[])
{
Base *pd = new Derived;
getchar();
return 0;
}
Referring to the sample code above, which one of the following statements is
true?
A.
A constructor needs to be added to Derived class.
B.
The pointer returned by new cannot be type cast from Derived* to Base*.
C.
A pointer to a Base class cannot point to an instance of a Derived class.
D.
Derived class... 阅读全帖
h*****g
发帖数: 312
14
来自主题: Quant版 - C++ online Test 2题
class Base{
public:
Base();
virtual ~Base();
};
class Derived: protected Base{
public:
virtual ~Derived();
};
int _tmain(int argc, _TCHAR* argv[])
{
Base *pd = new Derived;
getchar();
return 0;
}
Referring to the sample code above, which one of the following statements is
true?
A.
A constructor needs to be added to Derived class.
B.
The pointer returned by new cannot be type cast from Derived* to Base*.
C.
A pointer to a Base class cannot point to an instance of a Derived class.
D.
Derived class... 阅读全帖
(共0页)