假设,我写道
class A { };
Run Code Online (Sandbox Code Playgroud)
编译器应该提供(在需要时)
- 构造函数
- 析构函数
- 复制构造函数
- =运营商
这是所有编译器提供的吗?此列表中是否有任何添加或删除?
我有一个内存泄漏的问题.我有一个基类指针.从中,我new用来分配不同的派生类.然后,当我尝试delete使用引用(不是类型转换)的那些类时,我得到内存泄漏.我研究了这个问题,发现我应该在基类中添加一个虚拟析构函数,但是我尝试了这个并且仍然有内存泄漏; 也就是说,根据我的任务管理器,每次使用基类指针分配和删除派生类时,内存使用量会继续增加.我试图使它成为一个抽象的析构函数,并在派生类中添加了析构函数,但是我得到了一个未定义的引用错误.我也尝试将指针类型转换为派生类指针delete,但显然这会使程序崩溃.
有谁知道我应该怎么做?
示例代码:
class A {
public:
A();
~A() {};
virtual ~A(); /*or*/
virtual ~A()=0; /*or*/
/*or nothing?*/
}
class B: private A {
public:
B();
~B() {}; /*this?*/
/*or nothing?*/
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试读取java多行i18n属性文件.有这样的行:
messages.welcome=Hello\
World!
messages.bye=bye
Run Code Online (Sandbox Code Playgroud)
使用此代码:
import configobj
properties = configobj.ConfigObj(propertyFileName)
Run Code Online (Sandbox Code Playgroud)
但是对于多行值,它会失败.
有什么建议?
我已经从我的真实代码编辑了这个,所以它更容易理解.
基类:
class MWTypes
{
public:
virtual long get() { return (0); }
};
Run Code Online (Sandbox Code Playgroud)
派生类:(还有其他类,如char,double等等......)
class TypeLong : public MWTypes
{
public:
TypeLong(long& ref) : m_long(ref) {}
~TypeLong();
long get() { return m_long; }
private:
long& m_long;
};
Run Code Online (Sandbox Code Playgroud)
和存储类:
class RowSet
{
public:
void addElememnt(MWTypes elem);
MWTypes getElement();
std::vector<MWTypes> getVector() { return m_row; }
private:
std::vector<MWTypes> m_row;
};
Run Code Online (Sandbox Code Playgroud)
怎么称呼:
for (i = 0; i < NumCols; i++) // NumCols is 3 on this instance
{
switch(CTypeArray[i]) // this is an …Run Code Online (Sandbox Code Playgroud) 我可以在smalltalk中实现协同程序吗?
如果你的答案是否定的:为什么不呢?
或者如果是的话:你能举个例子吗?
我正在使用http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/#comment-103785开发GCM示例应用程序.
我无法注册gcm服务器.我收到以下错误.我已经搞砸了.但我找不到解决方案,所有的解决方案都是关于jar文件我已经做了所有的更改,但我无法得到它.
错误
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.gcm.GoogleCloudMessaging
com.sanjeev.integrationapp.RegisterActivity.registerGCM(RegisterActivity.java:80)
com.sanjeev.integrationapp.RegisterActivity$1.onClick(RegisterActivity.java:47)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
我的课程代码如下
public class RegisterActivity extends Activity {
Button btnGCMRegister;
Button btnAppShare;
GoogleCloudMessaging gcm;
Context context;
String regId;
public static final String REG_ID = "regId";
private static final String APP_VERSION = "appVersion";
static final String TAG = "Register Activity";
@Override
public void onCreate(Bundle savedInstanceState) { …Run Code Online (Sandbox Code Playgroud) I want to iterate over 100 values and select randomly 0 or 1, but end up with equal numbers of 0's and 1's,
The code below prints the counts:
import random
c_true = 0
c_false = 0
for i in range(100):
a = random.getrandbits(1)
if a == 1:
c_true += 1
else:
c_false += 1
print "true_count:",c_true
print "false_count:",c_false
Run Code Online (Sandbox Code Playgroud)
The output is:
true_count: 56
false_count: 44
Run Code Online (Sandbox Code Playgroud)
我希望计数是平等的
true_count: 50
false_count: 50
Run Code Online (Sandbox Code Playgroud)
如何更改代码以获得所需的结果?
我是C++的新手,我在OCaml和Python方面有更多的经验.我想通过制作一个播放"Morpion Solitaire"的程序来学习C++.我的开始有点困难.
在以下代码中:
typedef enum {NORTH, NORTHEAST, EAST, SOUTHEAST} direction;
char deltax[4] = { 0, 1, 1, 1};
char deltay[4] = { 1, 1, 0, -1};
class Coords {
private:
char x,y;
public:
Coords(char xx,char yy){
x = xx;
y = yy;
};
char get_x() const { return x;}
char get_y() const { return y;}
};
class Line {
private:
Coords orig;
direction dir;
Coords newcross;
public:
Line(char x1, char y1, direction d, char x2, char y2) {
orig = …Run Code Online (Sandbox Code Playgroud) 我为自己写了一个笔记工具作为我的第一个程序.它实际上在大多数情况下工作得很好,但有时程序会写一个额外的]或者}在所述文件的内部list或dict存储在所述json文件的内部.
它并不经常发生,我认为只有当我编写新的代码行或更改读取/写入所述文件的现有行时才会发生这种情况.我不是100%肯定,但这就是它的样子.
例如,我有一个list存储在一个文件中,我使用该indent=""标志来确保,因为它编写文件,如果我必须编辑所述文件,它对我来说更具可读性.有时在更改某些代码或添加代码后运行我的程序时,我收到一条错误,指出文件中有"额外数据".错误看起来像这样:
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 6 column 2 (char 5791)
Run Code Online (Sandbox Code Playgroud)
并且错误的原因将是这样的:
[
"Help",
"DataTypes",
"test",
"Variables",
]] # the error would be cause by this extra ] at the end of the list
Run Code Online (Sandbox Code Playgroud)
我不明白为什么程序有时会在我的json文件中的数据末尾添加和添加]或}?
当我打开文件或转储到文件时,我有什么问题吗?
以下是我用于打开文件和转储到文件的代码的一些部分:
path = "./NotesKeys/"
notebook = dict()
currentWorkingLib = ""
currentWorkingKeys = ""
#~~~~~~~~~~~~~~~~~~~< USE TO open all files in Directory >~~~~~~~~~~~~~~~~~~~
with open("%s%s"%(path,"list_of_all_filenames"), …Run Code Online (Sandbox Code Playgroud) 当我检查数据类型时,我想知道为什么char值返回为字符串类型。
请查看我的输入和输出。
输入:
a = 'c'
type(a)
Run Code Online (Sandbox Code Playgroud)
输出:
class 'str'
Run Code Online (Sandbox Code Playgroud) c++ ×4
python ×4
polymorphism ×2
android ×1
class ×1
class-design ×1
constructor ×1
coroutine ×1
dictionary ×1
file ×1
inheritance ×1
json ×1
list ×1
memory-leaks ×1
multiline ×1
properties ×1
random ×1
smalltalk ×1
vector ×1
virtual ×1