- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我试图通过不同的线程更新一个 atomic
变量并得到这个错误。这是我的代码。
class counter {
public:
std::atomic<int> done;
bool fn_write (int size) const {
static int count = 0;
if (count == size) {
done++;
count = 0;
return false;
} else {
count++;
return true;
}
}
};
int main() {
counter c1;
for (int i=0; i<50; i++) {
while (! c1.fn_write(10)) ;
}
}
我在第 8 行 done++
中收到以下错误。
error: no ‘operator++(int)’ declared for postfix ‘++’ [-fpermissive]
最佳答案
fn_write()
被声明为一个const
成员函数,其中done
数据成员不能被修改。
根据您的意图,您可以使 fn_write()
成为非常量:
bool fn_write (int size) {
... ...
}
或者,你可以让done
成为mutable
:
mutable std::atomic<int> done;
bool fn_write (int size) const {
... ...
}
关于c++ - std::atomic 错误:没有为后缀 ‘operator++(int)’ 声明 ‘++’ [-fpermissive],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48533476/
我不断得到: ../src/stack.cpp: In function ‘int main()’: ../src/stack.cpp:34:28: error: invalid conversion
#include #include #include #include 我需要有关此代码的帮助。我的编译器一直要求我使用 -fpermissive 选项,但我不知道在哪里输入它。我粘贴了下面的
我正在尝试使用 pthreads 将 Leibniz 的总和并行化以近似 PI。当我使用最新版本的 g++ 运行此代码时,会出现这两个错误,我真的不明白为什么,我正在这样编译:g++ pi2.cpp
我有一个 C 单头库,我想在我的 C++ 项目中使用它。通常,我只需包含该文件就可以了,因为 C++ 几乎是 C 的超集。但是,该库有一个跳过初始化的 goto,这违反了C++ 标准。 我可以通过在
#include #include using namespace std; typedef bool (*compare)(int,int); void SelectionSort(int *i
我正在尝试构建一个非循环树结构,每个节点都由一个字符串标识,每个分支节点都是 PrimMap 类型。同一代的所有节点都保存为 map 中的 Item 对象。这是缩写代码: class PrimMap
我知道这个问题已经回答了。但我只是想确认一下我的理解。 这是我的代码片段。来自this . #include using namespace std; class Base { void a
我写了下面的代码示例,我不得不使用 -fpermissive 来跳过错误/警告 #include #include using namespace std; int endOfProgram(){
我只是想知道 -fpermissive 标志在 g++ 编译器中的作用是什么?我得到: error: taking address of temporary [-fpermissive] 我可以通过将
我定义了两个不同的typedef结构:datatype_2d_1和datatype_2d_2,它们基本上都有两个 double 作为成员,但它们的定义不同。现在我有一个变量数据类型 z1 和一个指针
我正在使用 NDK (Android) 在 C++ 中构建一个库。输出告诉我一些代码被标记为错误,但可以通过使用 -fpermissive 标志来抑制。至少在我看来是这样。输出是: MyClass.c
我正在尝试构建一个带有静态数据成员的模板类,但当我尝试编译以下代码时收到此错误消息: |In instantiation of ‘T& T::t’:| 16|required from here| 1
我是 c++ 的新手,在 ubuntu 上使用 eclipse cdt 并在我的头文件中收到此错误: initializing argument 1 of 'std::map,Supplier*> E
我的想法是检查这个 dll 是否有我需要的版本,或者它是旧的还是新的?我正在尝试使用 THUNK/Trampoline 函数。 这是我在另一个 *.dll 文件中的用法。 int FilterVers
为什么编译器会在指示的行报错? class C { std::string s; public: C() { s = "";} ~C() {} void Set(con
我有一个类Cache,它的函数 write 指定为 bool write(const MemoryAccess &memory_access, CacheLine &cl); 我这样调用这个函数。 c
我在这个控制台应用程序中使用 Qt 4.5.1,当我想在 if 语句 行接收用户输入时,它收到此错误: iso c++ forbids comparison between pointer and i
我有一个数组,其大小在运行时确定。 cout>size1; int* scores=new int[size1]; 然后我填写这个数组分数。现在我想增加它的大小。我创建了一个新的动态数组。 int*
代码 int cycle_length(int i, int j) { int cycleLength = 0; for (int k = i; k cycle_length) {
我有以下代码: int Array::getSize(){ //do something } Movie Array::getMovie(int i){ //do something }
我是一名优秀的程序员,十分优秀!