小编Jim*_*m V的帖子

为什么这个枚举不能转换为int?

为什么下面的代码不能在g ++(C++ 14),MSVC(C++ 14)或ARM(C++ 03)下编译?

命名的Error实例调用整数构造函数,但匿名的Error实例无法解析.

class Error
{
public:
    Error(int err) : code_(err) {}
    const int code_;
};

enum Value
{
    value_1
};

int main()
{
    // compiles
    Error e(value_1);

    // does not compile under G++, ARM, or MSVC
    Error(value_1);
}
Run Code Online (Sandbox Code Playgroud)

G ++下的示例错误:( Coliru链接)

g++ -std=c++14 -O2 -Wall -pedantic -pthread main.cpp && ./a.out

main.cpp: In function 'int main()':
main.cpp:19:18: error: no matching function for call to 'Error::Error()'
     Error(value_1);
                  ^
main.cpp:4:5: note: candidate: Error::Error(int)
     Error(int err) : code_(err) {} …
Run Code Online (Sandbox Code Playgroud)

c++ enums

24
推荐指数
3
解决办法
3039
查看次数

为什么ARM使用两条指令来掩盖值?

对于以下功能......

uint16_t swap(const uint16_t value)
{
    return value << 8 | value >> 8;
}
Run Code Online (Sandbox Code Playgroud)

...为什么带有-O2的ARM gcc 6.3.0会产生以下程序集?

swap(unsigned short):
  lsr r3, r0, #8
  orr r0, r3, r0, lsl #8
  lsl r0, r0, #16         # shift left
  lsr r0, r0, #16         # shift right
  bx lr
Run Code Online (Sandbox Code Playgroud)

似乎编译器使用两个移位来屏蔽不需要的字节,而不是使用逻辑AND.编译器可以改用and r0, r0, #4294901760吗?

c++ assembly gcc arm

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

Python线程不会同时运行

我是多线程处理的新手,所以如果我屠宰条款或遗漏一些明显的东西,请原谅我.

下面的代码不会提供任何时间优势,而不是相继调用相同的两个函数的不同代码.


import time
import threading

start_time = time.clock()

def fibonacci(nth): #can be ignored
    first = 0
    second = 1
    for i in range(nth):
        third = first + second
        first = second
        second = third
    print "Fibonacci number", i + 1, "is", len(str(first)), "digits long"

def collatz(collatz_max): #can be ignored
    for n in range(collatz_max):
        n = n + 1 #avoid entering 0
        solution = []
        solution.append(n)
        while n != 1:
            if n % 2 == 0:
                n = n / …
Run Code Online (Sandbox Code Playgroud)

python multithreading

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

Peek定义(Alt + F12)在Visual Studio中不再起任何作用

虽然Goto Defnition如预期与重点工作F12,
热键Alt+ F12Peek Definition不再做任何事情.
如何恢复Alt+ F12功能?

visual-studio visual-studio-2015

5
推荐指数
3
解决办法
864
查看次数

有没有更快的方法使用命令行在C++中加载文件?

我想使用命令行从.txt中将一百万个随机整数加载到一个向量中:

program.exe < million-integers.txt
Run Code Online (Sandbox Code Playgroud)

我的代码可以运行,但需要几秒钟才能运行.我有什么办法可以让它更快吗?我在SO上找到了一些解决方案,但它们似乎都依赖于对文件路径进行硬编码.我希望能够通过命令行传递文件名.

vector<int> data;
int input;

while (cin >> input)
{
    data.push_back(input);
}
cout << "Data loaded." << endl;
Run Code Online (Sandbox Code Playgroud)

(在Win 8.1上使用Visual Studio的C++ noob)

编辑:在这种情况下,我知道可以做一些改进,因为我有其他人的.exe可以在一秒钟内完成.

编辑:所有整数都在同一行.

c++ command-line file input

4
推荐指数
2
解决办法
807
查看次数