我目前正在阅读w3schools的HTML教程(还没有CSS或JavaScript),我想知道为什么有这么多不同的标签看起来一样呢?
例如我看不出之间的任何(光学的)差kbd,samp并且code除了每个标签的"意义".
所以我的问题是:只是元信息不同这些标签?
我有一个线程,只有在某种情况进入时才需要工作.否则它只是迭代一个空的无限循环:
public void run() {
while(true) {
if(ball != null) {
// do some Calculations
}
}
}
Run Code Online (Sandbox Code Playgroud)
当循环实际上什么都不做但它必须检查它是否必须每次迭代进行计算时,它是否会影响性能?只在需要时才创建这个Thread对我来说不是一个选项,因为我实现Runnable的类是一个可以随时显示的可视对象.
编辑:以下是一个很好的解决方案吗?或者使用不同的方法(关于性能)更好?
private final Object standBy = new Object();
public void run() {
while(true) {
synchronized (standBy) {
while(ball != null) // should I use while or if here?
try{ standBy.wait() }
catch (InterruptedException ie) {}
}
if(ball != null) {
// do some Calculations
}
}
public void handleCollision(Ball b) {
// some more code..
ball = b;
synchronized (standBy) …Run Code Online (Sandbox Code Playgroud) 我们有一个班级Test和一个班级AnotherClass.两者都来自QObject.
Test.h:
class Test : public QObject
{
Q_OBJECT
public:
Test(QObject* parent);
~Test();
private:
AnotherClass* other;
};
class AnotherClass : public QObject
{
Q_OBJECT
public:
AnotherClass(QObject* parent);
~AnotherClass();
};
Run Code Online (Sandbox Code Playgroud)
TEST.CPP:
Test::Test(QObject* parent) : QObject(parent)
{
other = new AnotherClass(this);
}
Test::~Test()
{
delete other;
}
Run Code Online (Sandbox Code Playgroud)
other应该在Test-instance被销毁时自动销毁,因为Test它是父other,对吧?
other通过自己在~Test()或是否处于不确定阶段退出该计划,因为它试图删除同样的对象两次?我有一段代码,我不明白那一个typedef:
typedef void (inst_cb_t) (const char*, size_t);
Run Code Online (Sandbox Code Playgroud)
不,实际上意味着你可以使用inst_cb_t的void呢?但是第二个括号中的内容呢?
当我使用标准用户(也是管理员)登录时,该命令echo %PATH%返回系统路径+用户路径。如何只获取用户的路径?
例如,当我当前用户的路径是C:\ruby;C:\java\bin并且系统的路径是%SystemRoot%\system32;%SystemRoot%上面的命令返回时%SystemRoot%\system32;%SystemRoot%;C:\ruby;C:\java\bin,但我只想能够C:\ruby;C:\java\bin永久附加到用户的路径而不包含系统的路径垃圾。
我的目标是将目录附加到路径变量。setx PATH %PATH%;C:\ruby\bin我尝试使用由于系统路径而破坏了我的路径变量的命令来执行此操作。
如何加载YAML文件而不管其编码?
我的YAML文件可以用UTF-8或ANSI编码(这就是Notepad ++所说的 - 我猜它是Windows-1252):
:key1:
:key2: "ä"
Run Code Online (Sandbox Code Playgroud)
utf8.yml编码UTF-8,ansi.yml编码ANSI.我加载文件如下:
# encoding: utf-8
Encoding.default_internal = "utf-8"
utf8_load = YAML::load(File.open('utf8.yml'))
utf8_load_file = YAML::load_file('utf8.yml')
ansi_load = YAML::load(File.open('ansi.yml'))
ansi_load_file = YAML::load_file('ansi.yml')
Run Code Online (Sandbox Code Playgroud)
Ruby似乎无法正确识别编码:
utf8_load [:key1][:key2].encoding #=> "UTF-8"
utf8_load_file [:key1][:key2].encoding #=> "UTF-8"
ansi_load [:key1][:key2].encoding #=> "UTF-8"
ansi_load_file [:key1][:key2].encoding #=> "UTF-8"
Run Code Online (Sandbox Code Playgroud)
因为字节不一样:
utf8_load [:key1][:key2].bytes #=> [195, 164]
utf8_load_file [:key1][:key2].bytes #=> [195, 164]
ansi_load [:key1][:key2].bytes #=> [239, 191, 189]
ansi_load_file [:key1][:key2].bytes #=> [239, 191, 189]
Run Code Online (Sandbox Code Playgroud)
如果我错过Encoding.default_internal = "utf-8",字节也不同:
utf8_load …Run Code Online (Sandbox Code Playgroud) 考虑以下 mwe,实现一个重载乘法运算符的简单类:
#include <iostream>
using namespace std;
class A {
public:
double a;
A &operator*(double b)
{
a *= b;
return *this;
}
friend A &operator*(double b, A &m) { return m * b; } // (*)
};
int main()
{
A a;
a.a = 5.0;
a * 3.0;
std::cout << a.a << std::endl;
3.0 * a;
std::cout << a.a << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它编译并运行得很好,打印了预期的输出。但是 cppcheck 会给出以下警告。
tmp.cpp:15:48: error: Reference to temporary returned. [returnTempReference]
friend A &operator*(double b, A …Run Code Online (Sandbox Code Playgroud) 当函子从std :: function继承时,我不理解语法:
class do_sth : public function< any_type (another_type) >
{
bool operator() (string s) {...}
};
Run Code Online (Sandbox Code Playgroud)
我应该作为any_type和another_type使用什么?而且您能给我一个例子的例子,因为我还不了解它,它从std :: function继承的好处?
我想通过跳过第一个数组的第一个字符串对字符串数组的数组进行排序,但我只是不知道如何使用内置sort方法进行排序。我可以复制没有第一个元素的整个数组,然后对结果数组进行排序,但是没有更优雅的方法来做到这一点吗?
ar = [["zzzz", "skip", "this"], ["EFP3","eins","eins"], ["EFP10","zwei","zwei"], ["EFP1","drei","drei"]]
ar.sort!{ |a,b|
if a == ar.first # why doesn't
next # this
end # work ?
# compare length, otherwise it would be e.g. 10 < 3
if a[0].length == b[0].length
a[0] <=> b[0]
else
a[0].length <=> b[0].length
end
}
Run Code Online (Sandbox Code Playgroud)
我想要这样的结果:
["zzzz", "skip", "this"], ["EFP1","drei","drei"], ["EFP3","eins","eins"], ["EFP10","zwei","zwei"]
Run Code Online (Sandbox Code Playgroud)
排序方式 "EFP#"
编辑:如果重要的话,我使用的是 Ruby 1.8。
我正在StringEx用c ++ 编写我自己的字符串类(不用担心,只是为了练习)但是我没有通过为其分配字符串来创建我的类的实例:
StringEx string1 = StringEx("test"); // works fine
StringEx string2 = "test"; // doesn't work
string string3 = "test";
string1 = string3; // also works fine
Run Code Online (Sandbox Code Playgroud)
我重载了赋值运算符,所以它可以处理,std::string但我必须先创建一个对象StringEx.
如何通过为其StringEx指定字符串来创建新对象?甚至可以将c ++ "string"作为我的StringEx类的对象进行处理吗?
这是我StringEx.h 现在的作品
#ifndef STRINGEX_H
#define STRINGEX_H
#include <iostream>
#include <string>
#include <vector>
using namespace std; //simplyfying for now
class StringEx
{
private:
vector<char> text;
public:
StringEx();
StringEx(string);
StringEx(const char*); // had to add this
StringEx(vector<char>);
int …Run Code Online (Sandbox Code Playgroud) 我正在解析这个yaml文件
View:
from : 01.01.2007
to : 04.01.2007
driver : sun.jdbc.odbc.JdbcOdbcDriver
Run Code Online (Sandbox Code Playgroud)
在Scala中使用SnakeYAML,如下所示:
val stream = getClass.getResourceAsStream("/config_view.yml")
var configMap: Map[String, Any] = new Yaml().load(stream).asInstanceOf[java.util.Map[String, Any]].asScala
var view = configMap("View").asInstanceOf[java.util.LinkedHashMap[String, String]].asScala
view = view + ("from" -> "neu") // some test modifying
Run Code Online (Sandbox Code Playgroud)
我像这样转储它:
val fileWriter = new FileWriter(System.getProperty("user.home") + "\\Desktop\\test.yml")
new Yaml().dump(Map[String, Any]("View" -> view.asJava).asJava, fileWriter)
Run Code Online (Sandbox Code Playgroud)
这样可以保存新的yaml文件:
View: {driver: sun.jdbc.odbc.JdbcOdbcDriver, from: neu, to: 04.01.2007}
Run Code Online (Sandbox Code Playgroud)
但我希望它像这样保存:
View:
driver: sun.jdbc.odbc.JdbcOdbcDriver
from: neu
to: 04.01.2007
Run Code Online (Sandbox Code Playgroud)
如何告诉SnakeYAML将其保存为您在上面看到的所需格式?