我想在mac os x 10.8,山狮中禁用键盘快捷键command-w和command-q.这是因为它们干扰了我从xQuartz运行的终端内运行的emacs命令.所有帮助将不胜感激.
当您希望使用弱指针进行访问时,建议您首先通过锁定来获取指向所指向对象的强指针。如果先前删除了指向的对象,锁定可能不会成功。
在我看来,除非你在打破循环来决定什么是弱指针时犯了错误,否则锁定将会成功。所以你锁定只是为了交叉检查你的设计。
它是否正确?
我看过一些关于缓存的评论,但它们看起来像是对weak_ptr的滥用。但当然,一个人的虐待是另一个人的创新。我想听听意见。
以下代码为g ++版本4.6.2提供了一个例外,但是与g ++版本4.2.1一样按预期运行.在执行期间打印的消息表明在两种情况下都在从未构造的地址上调用析构函数.我想知道(a)哪些编译器是正确的,(b)为什么某些东西在没有被创建的情况下被破坏.非常感谢.
//------------------------------------------------------
#include <iostream>
using namespace std;
class Poly{
private:
float *coeff;
public:
Poly(){
coeff = NULL;
cout << "Created "<< this << endl;
}
Poly(Poly const & p){ // copy constructor
coeff = NULL;
cout << "Executed copy constructor.\n";
}
Poly operator=(Poly const & rhs){
cout << "Executed assignment. " << this << " = " << &rhs << endl;
}
Poly fun(){
Poly c;
return c;
}
~Poly(){
cout << "Destructor: " << this << endl; …Run Code Online (Sandbox Code Playgroud) 以下代码打开一个正确大小的窗口,w,h,但不在正确的位置x,y.
#include <iostream>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
using namespace std;
int main(int argc, char* argv[]){
Display *display; // A connection to X server
int screen_number;
Window canvas_window;
unsigned long white_pixel;
unsigned long black_pixel;
display = XOpenDisplay(NULL); // Connect X server by opening a display
if(!display){
cerr<<"Unable to connect X server\n";
return 1;
}
screen_number = DefaultScreen(display);
white_pixel = WhitePixel(display, screen_number);
black_pixel = BlackPixel(display, screen_number);
int x=0, y=100, w=300, h=400;
canvas_window = XCreateSimpleWindow(display,
RootWindow(display, screen_number),
x,y, // top left …Run Code Online (Sandbox Code Playgroud) 编译器不喜欢下面的主程序
int get1(ifstream &f){
int count;
f >> count;
return count;
}
int main(int argc, char** argv){
cout << get1(ifstream(argv[1])) << endl;
}
Run Code Online (Sandbox Code Playgroud)
错误消息是:
test.cpp: In function 'int main(int, char**)':
test.cpp:11:33: error: invalid initialization of non-const reference of type 's\
td::ifstream& {aka std::basic_ifstream<char>&}' from an rvalue of type 'std::if\
stream {aka std::basic_ifstream<char>}'
test.cpp:4:5: error: in passing argument 1 of 'int get1(std::ifstream&)'
Run Code Online (Sandbox Code Playgroud)
如果主程序被写为,这确实有效
int main(int argc, char** argv){
ifstream f(argv[1]);
cout << get1(f) << endl;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法使紧凑的第一种形式工作?
我有一个功能
void h(A const a){...};
Run Code Online (Sandbox Code Playgroud)
如果我这样做,行为是否有可能改变:
void h(A const &a){..same body as above..};
Run Code Online (Sandbox Code Playgroud)
您可以根据需要自由定义类型A. 当然.