static void f(String s)
{
s = "x";
}
public static void main(String[] args) {
String s = null;
f(s);
}
Run Code Online (Sandbox Code Playgroud)
为什么调用f(s)后s的值为null而不是"x"?
我需要从QHeaderView类派生的文本中绘制文本.但是这段代码不起作用.
void HeaderView::paintSection(QPainter *painter, const QRect &, int) const
{
painter->drawText(0, 0, "abcde");
}
Run Code Online (Sandbox Code Playgroud) 我有一些例外来自std::exception或std::runtime_error.唯一的方法是构造函数explicit MyExceptionX(const char *text = "") : std::exception(text) {}.有没有办法在不使用宏的情况下简化这些代码?
class MyException1: public std::exception
{
public:
explicit MyException1(const char *text = "") : std::exception(text) {}
};
class MyException2: public std::exception
{
public:
explicit MyException2(const char *text = "") : std::exception(text) {}
};
class MyException3: public std::exception
{
public:
explicit MyException3(const char *text = "") : std::exception(text) {}
};
//...
Run Code Online (Sandbox Code Playgroud) 有一个函数从头开始返回所有元素的平均值i + 1.
std::vector<double> f(const std::vector<double> &v)
{
std::vector<double> ret(v.size());
for (size_t i = 0; i < v.size(); ++i) {
ret[i] = std::accumulate(v.begin(), v.begin() + i + 1, 0.0) / (i + 1);
}
return ret;
}
Run Code Online (Sandbox Code Playgroud)
我该如何优化此功能?
我需要一个带有可变数量参数的模板函数.目前我的问题通过使用几个模板函数来解决.但是现在我需要在我的类函数和其他原因中创建一个wrap方法来将这个代码打包到一个函数中.
static void sendData(SSL *ssl, Command com)
{
std::string comStr(COM_SIZE, ' ');
memcpy(&comStr[0], &com, COM_SIZE);
sslWrite(ssl, comStr);
}
template<class T>
void sendData(SSL *ssl, Command com, const T &t)
{
std::string serialArg;
OByteStream obs(serialArg);
obs << t;
obs.flush();
const int serialArgSize = serialArg.size();
std::string comAndSerialData(COM_SIZE + serialArgSize, ' ');
memcpy(&comAndSerialData[0], &com, COM_SIZE);
memcpy(&comAndSerialData[COM_SIZE], &serialArg[0], serialArgSize);
sslWrite(ssl, comAndSerialData);
}
template<class T1, class T2>
void sendData(SSL *ssl, Command com, const T1 &t1, const T2 &t2)
{
std::string serialArgs;
OByteStream obs(serialArgs);
obs << t1 …Run Code Online (Sandbox Code Playgroud) 有一个按钮。
如何设置禁用按钮文本的颜色?
import tkinter as tk
root = tk.Tk()
frame = tk.Frame(root)
frame.pack()
button = tk.Button(frame, text="X", fg="red")
button.grid(row=0, column=0)
button['state'] = tk.DISABLED
root.mainloop()
Run Code Online (Sandbox Code Playgroud) 我需要编写一个单击Windows的应用程序。
如何将左键单击发送到窗口所在的某个屏幕x / y坐标?
c++ ×4
c++11 ×2
arguments ×1
c++14 ×1
java ×1
optimization ×1
paint ×1
python ×1
qheaderview ×1
qt ×1
sendmessage ×1
tkinter ×1
winapi ×1