我对大多数OO理论有了深刻的理解,但让我困惑的一件事是虚拟析构函数.
我认为无论什么以及链中的每个对象,析构函数总是会被调用.
你什么时候打算让它们成为虚拟的?为什么?
我有一个功课来实现一个简单的测试应用程序,下面是我目前的代码:
import java.util.*;
public class Test{
private static int typing;
public static void main(String argv[]){
Scanner sc = new Scanner(System.in);
System.out.println("Testing starts");
while(sc.hasNextInt()){
typing = sc.nextInt();
switch(typing){
case 0:
break; //Here I want to break the while loop
case 1:
System.out.println("You choosed 1");
break;
case 2:
System.out.println("You choosed 2");
break;
default:
System.out.println("No such choice");
}
}
System.out.println("Test is done");
}
}
Run Code Online (Sandbox Code Playgroud)
我现在要做的是,当0按下时,表示用户想要退出测试,然后我打破while loop并打印Test is done,但它不能那样工作,我知道原因可能是"break"打破了switch,我怎么能让它打破while loop呢?
假设我有这样一个ArrayList:
ArrayList<Integer> list = new ArrayList<Integer>();
Run Code Online (Sandbox Code Playgroud)
添加操作后:
list.add(2);
list.add(3);
list.add(5);
list.add(7);
Run Code Online (Sandbox Code Playgroud)
number 2如果我这样做,我想删除
list.remove(2);
Run Code Online (Sandbox Code Playgroud)
然后number 5将被删除,我怎么能删除number 2?并且假设我不知道索引number 2.
用于将照片上传到Facebook相册的新Facebook Android SDK就像这样的链接:
Bundle params = new Bundle();
params.putString("source", "{image-data}");
/* make the API call */
new Request(
session,
"/me/photos",
params,
HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
Run Code Online (Sandbox Code Playgroud)
令我困惑的是{image-data},它说照片应该被编码为multipart/form-data,但从params.putString("source", "{image-data}")我们可以看到第二个参数putString()应该是a String,我如何编码图像文件multipart/form-data并获得String格式的返回值?像这样:
public String getImageFormData(File image){
String imageValue;
...
return imageValue;
}
Run Code Online (Sandbox Code Playgroud)
或者我理解错了,我现在的问题是我有图像文件,如何使用上面的代码将图像成功上传到Facebook?
我是新的C++,我得到了error: '__locale_t' has not been declared我一些包含头文件,比如#include "ruby.h",#include <string.h>等等,但有一个为没有问题的#include <stdio.h>,我使用的Eclipse在Linux下,详细的错误的#include "ruby.h"和#include <string.h>是:
/usr/include/string.h:548: error: '__locale_t' has not been declared
/usr/include/string.h:549: error: nonnull argument references non-pointer operand (argument 1, operand 3)
/usr/include/string.h:552: error: '__locale_t' has not been declared
/usr/include/string.h:553: error: nonnull argument references non-pointer operand (argument 1, operand 4)
Run Code Online (Sandbox Code Playgroud)
包含的顺序是:
#include "Abc.h"
#include <string.h>
#include "ruby.h"
#include <stdio.h>
Run Code Online (Sandbox Code Playgroud)
Abc班级名称在哪里.
这是Abc类,没有添加除了include:
#include "Abc.h"
#include <stdio.h>
#include …Run Code Online (Sandbox Code Playgroud) 我是C的新手,我的代码行看起来像这样:
char user[16];
fgets(user,16,stdin);
Run Code Online (Sandbox Code Playgroud)
我在键盘上键入"zeyang",我还有另一个代码:
char pwname[1000];
pwname="zeyang";
Run Code Online (Sandbox Code Playgroud)
然后我strcmp用来比较用户和pwname:
strcmp(user, pwname);
Run Code Online (Sandbox Code Playgroud)
返回值是一个负数,我希望它是0,因为它们都是"zeyang".为什么不是0?
一个非常简单的C++代码,如下所示:
int main(int argc, char **argv){
std::cout << "argc: " << argc << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
编译 g++ -o hello hello.cpp
./hello u,输出是argc: 2;./hello u +,输出是argc: 3;./hello u *,输出是argc: 26,为什么26?c++ ×3
c ×2
java ×2
android ×1
argc ×1
break ×1
eclipse ×1
facebook ×1
linux ×1
openssl ×1
polymorphism ×1
shared-ptr ×1
while-loop ×1