错误:参数中无效地使用了无效表达式
Error: invalid use of void expression in parameter
由于timer_start函数,我的目标是每 1000 毫秒重复一次循环函数。
但一切都没有按计划进行:
g++ -DDMP_FIFO_RATE=9 -Wall -g -O2 -c -o demo_raw.o demo_raw.cpp demo_raw.cpp:在函数 'int main((' 中: demo_raw.cpp:66:33: 错误: 无效使用无效表达式 timer_start(loop((, 1000(; ^ make: *** [: demo_raw.o] 错误 1
构建失败(退出值 2,总时间:26 秒(
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include "I2Cdev.h"
#include "MPU6050.h"
#include <wiringPi.h>
#include <iostream>
#include <chrono>
#include <thread>
#include <functional>
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
void timer_start(std::function<void(void)> func, unsigned int interval)
{
std::thread([func, interval]() {
while (true)
{
func();
std::this_thread::sleep_for(std::chrono::milliseconds(interval));
}
}).detach();
}
void loop()
{
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
printf("ax: %6hdtay: %6hdtaz: %6hdngx: %6hdtgy: %6hdtgz: %6hdnnn",ax,ay,az,gx,gy,gz);
}
int main()
{
setup();
for (;;)
timer_start(loop(), 1000);
}
提前感谢您的帮助!
这里
timer_start(loop(), 1000);
您将返回值loop
作为第一个参数传递给timer_start
。但是loop
返回void
(又名什么都没有(,所以这没有任何意义。
您可能希望传递函数而不是调用它的结果,如
timer_start(loop, 1000);
您的timer_start
期望实际函数作为其第一个参数,而不是调用该函数返回的值(就像您包含的()
一样(。
只需删除这些括号:
int main()
{
setup();
for (;;)
timer_start(loop, 1000);
}
相关文章:
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- #define Dbg(fmt,..) (0) 是什么意思? 警告:表达式无效
- 二进制表达式的操作数无效 - 使用 for 和迭代器
- 错误:参数中无效地使用了无效表达式
- 为什么这个正则表达式C++在括号表达式中抛出无效范围异常?
- 二进制表达式 cout 问题的无效操作数
- 你能防止 std::regex 在无效表达式上抛出异常吗?
- 在c++std::函数的上下文中无效使用void表达式
- C++ 解决方法:"从类型"B*"的表达式初始化类型"C*&"的引用无效"
- 二进制表达式的操作数无效?
- 二进制表达式的操作数无效("常量字符*"和"常量字符*")
- 如何修复"二进制表达式的无效操作数"?
- 没有变量声明为函数,但错误:二进制表达式的操作数无效
- 如何修复此错误:二进制表达式的操作数无效("std::vector<double>"和"double")?
- 如何将无效操作数修复为二进制表达式
- 错误:二进制表达式的操作数无效(映射使用查找函数错误)
- 无效地将 void 表达式与队列和 .pop() 一起使用
- 错误:二进制表达式('float' 和 'float')返回的无效操作数 (x & (1 << 31)) == 0
- 如何将无效操作数修复为带有字符串的二进制表达式?
- 当使用无效表达式时,概念是否应该无法编译?