由买买提看人间百态

topics

全部话题 - 话题: myclass
首页 上页 1 2 3 下页 末页 (共3页)
x******a
发帖数: 6336
1
来自主题: Programming版 - python一问
请问这两个有什么区别?
list_of_class= [myclass() for i in range(10)]
list_of_class= [myclass()]*10
我用
for i in range(10):
list_of_class[i].update(some_data)
第一个得到10个不同的myclass objects。第二个得到10个相同的。
多谢!
d****i
发帖数: 4809
2
不提供头文件不行吧,头文件相当于接口,没有接口人家怎么用你的库?你可以在你的
cpp文件里面实现你的类,然后在最后加上instantiation,比如
template class MyClass;
template class MyClass;
template class MyClass;
...
这样你只需提供lib和相应的头文件,而把你的实现代码隐藏
z****e
发帖数: 54598
3
来自主题: Programming版 - 问一个intellij idea的快捷键
就是比如
public static MyClass myClass;
当光标还在public的时候,怎样让它快速跳到static去
当还在static的时候,如何快速跳转到MyClass上去
也就是下一个单词的词首位置
我不知道这个英语怎么说,所以找不到,一大堆快捷键,不想一个个找过去
偷懒就问了,我记得我看到有人这么搞过,ide用顺手了噼里啪啦狂快
m******9
发帖数: 968
4
来自主题: JobHunting版 - 一道 C++ 的题。
MyClass * pClasses[500];
pClasses[idx] = new MyClass(int);
m*******i
发帖数: 370
5
来自主题: JobHunting版 - 一个data structure design的问题,求助
thanks! 应该是这个。不知道怎么implement的
是使用array吗?比如
MyClass* obj_ptr=new MyClass[N];
根据hash key insert to the array, 然后maintain pointer根据insert 的顺序指向
上一个insert的obj和下一个将要insert的obj?
不知道是不是这样?给解释一下吧,多谢!
l****l
发帖数: 8
6
来自主题: JobHunting版 - Code for Singleton design pattern
myclass.getinstance(); => myclass::getinstance();
e********3
发帖数: 229
7
1. 给定2 threads, 每个thread相隔一个小时运行一次.他们运行时会调用myclass 里
的doWork method. 这个method就是update myclass里的一个field.比如一个int filed
.这个dowork method保证在2分钟之内完成. thread会在一开始运行时就call这个
method. 请问对这个method我们需要synchronization吗?
2. 如何implement 领英的social graph. 要求给定2个user,你能快速查出这2个user是
不是直接connected或者间接connected.比如2nd connection, 3rd connection.
3. 接2, 如果要求能查出某个user有多少个direct connections呢?
求大牛解惑
z****e
发帖数: 54598
8
我觉得应该加上同步
因为虽然保证在2m内完成
那鬼知道呢,如果真发生了在1h内完不成的情况呢?
其次就是,这里有明显的side effect
都update myclass field了,显然这个method不是pure
最好逻辑代码放到myclass里面去
封装进去,然后synchronized所有methods
这样就可以互斥了,当然最理想的是从结构上打掉这种内存共享机制
除非不得不用,比如做pvp gaming
s******e
发帖数: 96
9
来自主题: Database版 - 请教一个MFC database 的问题
VC++,MFC,database 问题
1. Describe CObList, provide a sample that defines a class named MyClass
derived from CObject , then builds a CObList with a few of MyClass objects
in the process heap, then removes your CObjects from the list.
2. Describe try/catch logic and add try/catch logic to the sample in your
sample 1) above
3. Suppose you have an ODBC Data source named MyDB, provide a sample that
opens a CDatabase object using MyDB data source. Build a CString object
containing SQL to insert a rec
c**t
发帖数: 26
10
来自主题: Java版 - 库里有一个函数名也叫Time
库里有一个class也叫Time, 如果想用这个函数而不是Java里的Time,
该怎么办呢?
我是这么用的:
import com.Time;
public class myclass
{
Time a= new Time(String c, 1);
....
};
用javac编译时出错。
又试了一下
public class myclass
{
com.Time a= new com.Time(String c, 1);
....
}
还是出错,怎么用是正确的呢?
谢谢
c**t
发帖数: 26
11
来自主题: Java版 - 怎么返回空指针呢?
public class myclass
{
private String [] typeId=null;
public myclass(){};
public String [] getTypeId(Res a)
{
int i=0;
for(i=0;i {
if(a[i]!=null)
{
typeId[i]=new String("Levl " + i);
}
}
return typeId;
}
}
调用getTypeId时的a不是空的,但getTypeId返回时出错,说是NullPointerExceptio
c*i
发帖数: 749
12
运行到哪一步装载class?
ClassA MyClass;
MyClass = new ClassA();
c*****t
发帖数: 1879
13
1. You cannot change the content of a jar file package.
2. A normal way of getting resource from jar package is:
myClass.class.getResourceAsStream ("path");
if the resource file is located in the same directory as myClass,
then all you need to is to specify the name of the file as path.

directory
p***p
发帖数: 559
14
来自主题: Java版 - synchronization 锁住了什么?
synchornized(obj)
{
Codes to be protected
}
1 what i want to protected is the code, not the obj. To be sure only 1 thread
excute the codes a time. It is ok.
But, Question
2 so how should I choice the Obj, for design? When should I use synchornized(this)? what does it mean, for design.
synchornized(this) {
......
}
3 for
Class myclass {
int myObj=1;
synchornized void myMethod() { // not static
int something = myObj;
..........
}
}
myclass mca,mcb;
mca.myMethod();
mcb.myMethod()
c******n
发帖数: 4965
15
来自主题: Java版 - very archaic issue :
ur code:
public class MyClass {
public void main(String args[]){
while ( true ) System.out.println();
}
}
let's say u run it like
ssh remote_host " java -cp myjar.jar MyClass "
and then after a while , press Control-C
would the java code still be running on the remote side ?? :)
why??
it turns out to be a very nasty problem covering many aspects of
Signals, shell, and java, and ssh
c******n
发帖数: 4965
16
来自主题: Java版 - what is your opinion in this case?
/* generate a bunch of "random" numbers
taken in serial one by one from a list of numbers in
a given file
*/
class RandomGen(
public RandomGen() throws IOException {
InputStream ios = ..... open "rand.txt" in CLASSPATH;
//
read the file into memory,
}

int idx;
public Integer gen() {
return list_of_numbers[idx++];
}
}
something like the above.
the problem is that the constructor throws IOException, so if I use this
class, and most likely I us... 阅读全帖
b***i
发帖数: 3043
17
来自主题: Java版 - 遇到Swing的一个问题
我的程序代码突然不好用了,是从别人那里拿来的代码,我不停地修改补充。程序中用
一个类来显示一个窗口,之后隐藏。这个窗口变量本身是不需要每次new产生,整个程
序运行就构造一次。鼠标点击一个按钮后,这时把窗口加入到frame中---add(panel,
int)。
现在的问题表现在,第一次可以看到窗口,然后正确隐藏。之后按钮无论怎么按,窗口
都不出现。调试,发现,所有窗口位置参数都对,按钮event也执行了,就是看不见窗
口。今年1-1编好的jar还好用,可以每次看到窗口,可是现在的代码我在eclipse里面
运行就这样了。
我倒是解决了,但是我想看看大家的意见,我主要是想知道为什么?
原相关代码:
class Myclass extends JPanel{
JPanel myPanel;
Myclass(){myPanel=new....}
public void actionPerformed(ActionEvent e){
...
myPanel.add(...内容);
mainPanel.add(myPane... 阅读全帖
t****t
发帖数: 6806
18
来自主题: Programming版 - [菜鸟问题]类模板问题
typename MyClass::Inner MyClass::CreateInner(int v) const
~~~~~~~~
{...}
r****r
发帖数: 115
c********e
发帖数: 383
20
这个c++ template, complete guide 的前言里面有讲到过,确实有一些不同。
template在这里就像是个macro一样。
作者强力推荐const方后面,我看过后忘记了。感觉对于一般人没什么大用
t****t
发帖数: 6806
21
能不能说说有啥不同? 我试了试好象是一样的嘛. 如果T是int*,
那const T和T const都是int * const.
t****t
发帖数: 6806
22
呵呵,刚好google book可以翻翻前言
你说的那一段看见了, 作者的确证实了
const T === T const, unless T is a macro (textual replacement)
which is what I said.
of course, if you textual replace T with char*, then
const char * != char * const, but that's not what I said
t*****g
发帖数: 1275
23
Yea, I was wrong on that. T = char * doesn't make const T = const char *, it
's more like const (char *) where char * has higher priority.
y***y
发帖数: 295
24
假设我的class MyClass overload了function call operator
MyClass::operator()(int, int);
我如何能够通过this调用这个operator呢?
试过this.operator ()(a, b);
在gcc下编译似乎不通过...
谢谢!!!
p****o
发帖数: 1340
25
来自主题: Programming版 - 一个partial specialization的问题
我定义了一个模板类:
template class myclass
{
typedef T datatype;
...
};
我希望当使用myclass的时候,这个datatype
的定义不是T,而是一个另外的类型S。我的问题是这个
是不是可行的?如果可以的话,syntax是什么呢?
我可以用full specialization的,不过这个类有好多
函数的,所以不想这样搞。google了半天也未果。
谢了!
d*****u
发帖数: 17243
26
来自主题: Programming版 - C++ 什么时候用 "new" ?
用new的话可以不要变量名,直接用指针访问
比如
MyClass *Prt;
Prt = new MyClass(12);
否则好像没啥区别
g*********s
发帖数: 1782
27
来自主题: Programming版 - stl Compare为何需要重载()?
Function object重载()是C++的规定吗?为何选择()?手头没有D&R,这里有什么故事么?
struct myclass {
bool operator() (int i,int j) { return (i };
// using object as comp
sort (myvector.begin(), myvector.end(), myclass());
t****t
发帖数: 6806
28
no difference for user-defined class. for built-in types, () will do 0-
initialize.
X****r
发帖数: 3557
29
好吧,你快一点点,我自砰。
f******y
发帖数: 2971
30
Why does it work this way?
t****t
发帖数: 6806
31
because standard said so.
d****i
发帖数: 4809
32
来自主题: Programming版 - c++ 宏的问题
一点小错误,这一行应该写成
SomeKindofClass myClass = SomeKindofClass();
=> SomeKindofClass myClass;
C++里面stack变量对象创建时不用call default ctor,直接按照C的办法来。
d****i
发帖数: 4809
33
C++有像Java那样的in-class member initializers了?是不是就是这样的:
class MyClass {
private:
int member1 = 0;
bool member2 = true;
};
如果是这样的话,这是违反C++的常理的,因为C++的类的声明应该出现在头文件中
MyClass.h,头文件中只管声明,不管定义,成员变量的定义应该只在cpp文件中出现,
这个是C++的convention,static const变量除外。

threading
的。
m*********a
发帖数: 3299
34
来自主题: Programming版 - 今天给c++震惊了
还有这个知道了。 code::block 还没有fix这个bug
这是为啥我都晕了,在code::block都是可以assignable lvalue的
但是标准应该是一个是lvalue一个是rvalue
MyClass & f()//return lvalue
MyClass f()//return rvalue
Assignment to rvalues
Visual Studio 2012 didn’t forbid assignment to rvalues as required by the
standard:
struct Dummy
{
int _x;
};
Dummy get_dummy()
{
Dummy d = { 10 };
return d;
}
get_dummy()._x = 20;
h**l
发帖数: 168
35
来自主题: Programming版 - const int foo()啥意思?
Another way to disable such bizarre assignment to r-value is to do the
following
MyClass& operator=(const MyClass& other) && = delete;
while at the same time allow move for r-value.
b***i
发帖数: 3043
36
我们项目中有很多warning,其中有大量我认为是错误的,比如
const MyClass& GetSome(){
return MyClass(... constructor);
}
这种虽说编译不出错,但是是不是不对?
我跟招我那个人讨论过,他说以前是编译直接出错,现在警告,但是C++11可以允许。
他说,这是extend the life time of temporary。
但是 我认为他说的 不对 。他说的 其实 是
const MyClasss& abc = someFunc(); // someFunc() returns an object
而 例子 中 是返回一个引用,但是把刚刚构造的临时(rValue)对象返回了引用是堆
栈错误。这个我试过了,是Undefined。我同事有个演示,能正常使用。我把他
constructor里面的std::cout删掉后就不能正常使用了。
这种是不是得告诉公司,不能这么写啊?虽然现在没有问题,主要是这些代码没有被调
用过。
A**u
发帖数: 2458
37
来自主题: Quant版 - 被Citi老中黑了
函数的原型
int f(int, double);
MyClass(const Myclass&);
i****1
发帖数: 445
38
来自主题: Quant版 - 被Citi老中黑了
应该是
MyClass(const MyClass & const);吧。
我记得引用本省也是const的
l**n
发帖数: 88
39
来自主题: JobHunting版 - 一道 C++ 的题。
is a loop necessary?
for(int i=0; i<500; i++) {
pClasses[i] = new MyClass(int);
}
l**n
发帖数: 88
40
来自主题: JobHunting版 - 一道 C++ 的题。
I am a new learner of C++, can you elaborate a little bit? Thanks a lot!
why "pClasses[idx] = new MyClass(int);" works?
what is idx?
f****4
发帖数: 1359
41
来自主题: JobHunting版 - 发个C++语法问题,调节一下气氛
呵呵,你这样描述有个小问题
private这些关键字,是用来实现class封装的
所以,无关class的objects,只和class有关系
m对别的class都是私有的
但是m对myclass的所有函数都是可访问的
t*******y
发帖数: 637
42
来自主题: JobHunting版 - 问一道c++面试题
Suppose you're responsible for writing class MyClass as part of a static
library.
a) How do you enforce that a single instance of this class be used at
compile-time? b) How do you enforce that instances only be allocated on the
stack, but not on the heap, at compile-time?
a)应该是用singleton
b)呢?
y*******o
发帖数: 6632
43
来自主题: JobHunting版 - 再问一个碰到的C++问题
Q2 should be C right?
C) The problem is that the destructor of "myclass" is not called.
a********r
发帖数: 218
44
来自主题: JobHunting版 - 问一道C# interview testing quesiton
class MyClass
{
private int numberOfCalls = 0;
private int numberOfLetters = 0;
static void ReverseString(String strIn)
{
char temp;
for (int i = 0; i < strIn.Length; i++)
{
temp = strIn[i];
strIn[i] = strIn[strIn.Length - i];
strIn[strIn.Length - i] = temp;
}
numberOfCalls++;
C... 阅读全帖
f*******t
发帖数: 7549
45
来自主题: JobHunting版 - 问一道C# interview testing quesiton
1.成员变量应该设成static
2.numberOfLetters多余
3.for (int i = 0; i < strIn.Length; i++) 从头做到尾相当于又把string还原了,
应该是i < strln.Length / 2
4.strIn[strIn.Length - i]当i=0时越界,应该是strIn[strIn.Length - i - 1]
5.MyClass和函数都要加public,否则可能无法从其它namespace访问
6.输出函数自带format功能,不需要string.format()
d****o
发帖数: 1055
46
来自主题: JobHunting版 - 问一道c++面试题
#include
using std::cout;
using std::endl;
class thing
{
public:
thing(){cout << "hello, world" << endl;};
};
thing myclass;
int main(void)
{
cout << "Started" << endl;
return 0;
}
f********a
发帖数: 165
47
import java.util.HashMap;
public class MyClass {

public static HashMap hashMap = new HashMap Integer>();
private String s = new String();

public void log1(String msg1, String msg2){
synchronized(hashMap){
System.out.println(msg1);
System.out.println(msg2);
}
}

public void log2()
{
hashMap.put(new String("123"), new Integer(1));
}
public static void log3(String ms... 阅读全帖
w********s
发帖数: 1570
48
来自主题: JobHunting版 - bloomberg非典型面试
typedef MyVector MyClassPtrVec;
l******k
发帖数: 586
49
就下面这段代码
std::unique_ptr obj;
std::function f = [&](int v) { obj->DoSomething(v); };
有什么办法检测 f 是否depend on obj?
s********e
发帖数: 340
50
贡献一个Java 程序 面试题,看不懂为啥。请指教!
经运行,输出结果为 8 3 4
而且,我发现如果我修改了byte arr[] = new byte[]{8,3,4,5}; 的数组值,输入也修
改,
总是arr数组值是一致的。高人能给解释一下这个程序是为什么吗?谢谢!
import java.util.Collection;
import java.util.Set;
public class MyClass {

public static void main(String[] args){
byte arr[] = new byte[]{8,3,4,5};
for(final int i: getCharArray(arr))
System.out.print(i +" ");
}

static char[] getCharArray(byte[] arr){
char[] carr = new char[4];
int i=0;
fo... 阅读全帖
首页 上页 1 2 3 下页 末页 (共3页)