小编ror*_*oro的帖子

这段代码不应该抛出一个模糊的转换错误吗?

我有两个班,A并且B,每个定义转换B.A有一个转换运算符B,B有一个构造函数A.不应该打电话static_cast<B>暧昧吗?使用g ++,这段代码编译并选择转换构造函数.

#include<iostream>

using namespace std;

struct B;
struct A {
    A(const int& n) : x(n) {}
    operator B() const;         //this const doesn't change the output of this code
    int x;
};

struct B{
    B(const double& n) : x(n) {}
    B(const A& a);
    double x;
};

A::operator B() const           //this const doesn't change the output of this code
{
    cout << "called A's conversion …
Run Code Online (Sandbox Code Playgroud)

c++ casting

14
推荐指数
1
解决办法
385
查看次数

我可以定义一个指向std :: function类型对象的函数指针吗?

类似于以下内容:

#include <functional>

int main()
{
    std::function<int(int)> func = [](int x){return x;};
    int* Fptr(int) = &func; //error
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

temp.cpp: In function ‘int main()’:
temp.cpp:6:15: warning: declaration of ‘int* Fptr(int)’ has ‘extern’ and is initialized
  int* Fptr(int) = &func; //error
               ^
temp.cpp:6:20: error: invalid pure specifier (only ‘= 0’ is allowed) before ‘func’
  int* Fptr(int) = &func; //error
                    ^
temp.cpp:6:20: error: function ‘int* Fptr(int)’ is initialized like a variable
Run Code Online (Sandbox Code Playgroud)

从lambda函数到函数指针的更直接的方法也是有用的.

c++ lambda c++11

9
推荐指数
1
解决办法
411
查看次数

超线程如何影响并行化?

我在OpenMPHyperThreaded CPU上使用代码.

如果其他条件相同,那么非HyperThreaded CPU的性能会如何变化

我注意到100%的处理器利用率,无论我运行多少线程,但改变线程数确实提高了性能.怎么会这样?

非INTEL多线程CPU的故事是否相同?

c++ parallel-processing multithreading openmp hyperthreading

6
推荐指数
1
解决办法
517
查看次数

将 grep 的退出代码存储在 makefile 变量中

我在 makefile 中使用 shell 函数进行 grep 搜索:

结果 = $(shell grep find in)

我可以只存储退出代码而不是存储 grep 的结果吗?或者,是一种检查 RESULT 是否为非空的方法?

terminal command-line makefile

4
推荐指数
1
解决办法
1518
查看次数

这(简单)lambda函数有什么问题?

捕获的变量有问题,但我无法弄清楚是什么.我得到的错误是

error: no matching function for call to ‘applyFunc(int, main()::<lambda(int)>)’
  applyFunc<int,int>(0,[=](int z) -> int{return z + xx;}); //error!
Run Code Online (Sandbox Code Playgroud)

什么是错的任何见解?

//given input x and function func, return func(x)
template <typename T, typename U>
U applyFunc( T x, U func(T) )
{
    return func(x);
}

int main()
{
    int xx = 2;
    applyFunc<int,int>(0,[](int x) -> int {return x + 1;}); //no error
    applyFunc<int,int>(0,[=](int z) -> int{return z + xx;}); //error!

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编辑:修复<functional>中的函数对象.

#include <functional>

template <typename RET, typename INPUT>
RET …
Run Code Online (Sandbox Code Playgroud)

c++ lambda c++11

3
推荐指数
1
解决办法
372
查看次数

emacs keybinding在终端中不起作用

我在.emacs文件中设置了以下键绑定:

(global-set-key (kbd "C-S-M-w") 'windmove-up)
(global-set-key (kbd "C-S-M-s") 'windmove-down)
(global-set-key (kbd "C-S-M-d") 'windmove-right)
(global-set-key (kbd "C-S-M-a") 'windmove-left)

(global-set-key (kbd "C-S-a") 'shrink-window-horizontally)
(global-set-key (kbd "C-S-d") 'enlarge-window-horizontally)
(global-set-key (kbd "C-S-s") 'shrink-window)
(global-set-key (kbd "C-S-w") 'enlarge-window)
Run Code Online (Sandbox Code Playgroud)

当他们在自己的窗口时,他们工作得很好.但是,如果我在终端(emacs -nw)中运行它,则不会加载键绑定.即使在加载.emacs文件后,我仍然没有键绑定.

当我使用emacs守护进程并在客户端和终端中打开时,这是相同的故事.如果重要的话,我在linux机器上.

emacs terminal key-bindings

1
推荐指数
1
解决办法
1419
查看次数