这是一个小程序:
#include <iostream>
using namespace std;
int main() {
f();
system("pause");
}
void f() {
static int x = 20 ;
class tester {
public :
tester() {
cout << x ;
}
} x1;
}
Run Code Online (Sandbox Code Playgroud)
我在这里得到的错误是:错误C3861:'f':找不到标识符
如果我将函数f置于main之上,我将获得所需的输出.
为什么会这样?
我被告知程序执行开始于main.据此,代码也应该在第一种情况下运行.
编译器如何开始阅读程序?
#include <iostream>
using namespace std;
class Tester {
public:
Tester(int x);
~Tester();
int who;
} Tester_g_1(1) , Tester_g_2(2);
Tester::Tester(int id) {
cout << "Intializing" << id << endl ;
who = id;
}
Tester::~Tester() {
cout << "Destroying" << who << endl;
}
int main() {
Tester localObj(3);
cout << "This is not the first line to be displayed";
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
Intializing1
Intializing2
Intializing3
This is not the first line to be displayedPress any key to continue …Run Code Online (Sandbox Code Playgroud) #include <iostream>
#include <direct.h>
using namespace std;
int main() {
if( _mkdir("d:\\a\\b") == 0 ){
cout << "success";
} else if ( _mkdir("d:\\a") == EEXIST ) {
cout << "Directory was not created because dirname is the name of an existing file, directory, or device.";
}
else if ( _mkdir("d:\\a") == ENOENT ) {
cout << "Path was not found.";
}
}
Run Code Online (Sandbox Code Playgroud)
在运行程序时,输出是意外的.(大多数时候是失败.我不知道原因)
有时我看到成功.很多时候,如果我删除双斜杠\\单斜杠\消息是成功的.这件事让我很生气.为什么会这样?有backslashes问题吗?
UPDATE
在visual c ++ 2010 express edition中,当我按下CTRL + …
public class Normal {
public string name; // name is public
public String getName() {
return name ;
}
public String setName(String newName) {
name = newName ;
return name ;
}
public static void main(String args[]) {
Normal normal = new Normal();
normal.setName("suhail gupta");
System.out.println( "My name is : " + normal.getName() );
}
}
Run Code Online (Sandbox Code Playgroud)
新课程从这里开始
public class Different {
private string name; // name is private
public String getName() {
return name ;
}
public String setName(String newName) …Run Code Online (Sandbox Code Playgroud) 如何读取AudioInputStream特定数量的字节/微秒位置?例如 :
AudioInputStream ais = AudioSystem.getAudioInputStream( new File("file.wav") );
// let the file.wav be of y bytes
Run Code Online (Sandbox Code Playgroud)
现在我想获得一个AudioInputStream具有高达某些x字节数据的数据x < y.
我怎样才能做到这一点 ?
我一直在努力思考但没有任何方法可以做到这一点?
以下是irbshell 中的简单语句.是什么nil在输出是什么意思?为什么它与if块中的print语句一起出现?
irb(main):062:0> if(x==20 && y==30)
irb(main):063:1> print("if statement working !")
irb(main):064:1> else
irb(main):065:1* print("else statement working !!")
irb(main):066:1> end
if statement working !=> nil # what does nil represent here ?
Run Code Online (Sandbox Code Playgroud) 打印以下代码NoMethodError.我不明白原因.虽然我调用的方法是私有的,但我从类中调用它.不能类var访问它的私有变量/函数?我可以用Java做到这一点.
class Tester
private
def func_pri
puts("From a private function")
end
protected
def func_prot
puts("From a protected function")
end
public
def func_pub
puts("From a public function")
end
public
def caller(object)
object.func_pub
object.func_pri # This statement causes error
object.func_prot
end
end
o = Tester.new
o.caller(o)
Run Code Online (Sandbox Code Playgroud) 在下面的脚本中,我尝试在DOM树中移动,但是我没有得到我期望的输出.
这里只有一小段html:
<p id="para">This is inside the <em>p</em> tag.</p>
Run Code Online (Sandbox Code Playgroud)
当我穿过树时,这就是我得到的:
Node Name : P
Node Type : 1
Node Value : null
Node Name : HTML
Node Type : 1
Node Value : null
Run Code Online (Sandbox Code Playgroud)
<html>
<head>
<title>JavaScript</title>
</head>
<body>
<p id="para">This is inside the <em>p</em> tag.</p>
<script type="text/javascript">
function nodeStatus(node) {
document.write("Node Name : " + node.nodeName + "<br />");
document.write("Node Type : " + node.nodeType + "<br / >");
document.write("Node Value : " + node.nodeValue …Run Code Online (Sandbox Code Playgroud) 以下方法有什么区别:
jButton.getModel().isArmed()
jButton.getModel().isSelected()
jButton.getModel().isPressed()
Run Code Online (Sandbox Code Playgroud)
我不明白文档说的是什么,isArmed其余两个有明显的文档.但我不知道他们的表现如何.
发生了一些奇怪的事情。当我进入同步块时,我尝试打印线程的名称。在打印语句之后,我暂停了100000秒。
@Override
public int getNextAvailableVm() {
synchronized(this) {
System.out.println(Thread.currentThread().getName());
try {Thread.sleep(100000000);}catch(Exception exc){}
String dataCenter = dcc.getDataCenterName();
int totalVMs = Temp_Algo_Static_Var.vmCountMap.get(dataCenter);
AlgoHelper ah = (AlgoHelper)Temp_Algo_Static_Var.map.get(dataCenter);
.
.
.
}
}
Run Code Online (Sandbox Code Playgroud)
但是在运行此方法时,将打印两个线程的名称。
Thread-11
Thread-13
Run Code Online (Sandbox Code Playgroud)
在此之后,会出现长时间的停顿。这是为什么 ?当第一个线程尚未离开同步块时,两个线程如何进入同步块?
java ×4
c++ ×3
visual-c++ ×3
oop ×2
ruby ×2
audio ×1
dom ×1
html ×1
javascript ×1
javasound ×1
jbutton ×1
null ×1
private ×1
swing ×1
synchronized ×1