Arduino编译器抛出"invalid type argument of unary *"
Arduino compiler throws "invalid type argument of unary *"
我正在尝试编程一个非阻塞的led闪烁。
为此,我编写了一个小课程:
03: class timer {
04: private:
05: int startMillis;
06: int delayMillis;
07: public:
08: timer ( int pDelay ) {
09: reset ( pDelay );
10: }
11: void start () {
12: startMillis = millis();
13: }
14: void reset ( int pDelay ) {
15: delayMillis = pDelay;
16: }
17: boolean checkTimer () {
18: if ( (millis() - startMillis) >= delayMillis ) {
19: return true;
20: } else {
21: return false;
22: }
23: }
24: };
然后我想在loop()中做这样的事情:
42: void switchLed (int *pPin, timer *pTimer) {
43: if ( (*pTimer->checkTimer()) == true ) {
44: if ( bitRead(PORTD, *pPin) == HIGH ) {
45: digitalWrite(*pPin, LOW);
46: } else {
47: digitalWrite(*pPin, HIGH);
48: }
49: *pTimer->start();
50: }
51: }
我用参数"(&led[0],&ledTimer01)"调用loop()中的switchLed()函数。我认为它应该工作,但我的编译器说
nonblockingblink:5: error: 'timer' has not been declared
nonblockingblink.ino: In function 'void switchLed(int*, timer*)':
nonblockingblink:43: error: invalid type argument of 'unary *'
nonblockingblink:49: error: void value not ignored as it ought to be
问题出在哪里?感谢您的帮助:)。
pTimer->checkTimer()
具有类型boolean
所以这个:
*pTimer->checkTimer()
无效,因为boolean
不是指针类型。
其他函数也是如此,为什么要使用*
运算符?这是不正确的:
*pTimer->start();
这是正确的:
pTimer->start();
或
(*pTimer).start(); // equivalent to above, prefer the above form
您使用两种类型的指针去引用。首先使用->
访问pTimer
结构成员,然后对非指针类型(checkTimer
返回的boolean
)再次使用*
。去掉星号,它就可以工作了。
相关文章:
- 表示"accepting anything for this template argument" C++概念的通配符
- Usages of std::move
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 具有变量Number of Arguments的std::函数的矢量
- Capacity of a deque
- Deprecation of _writeBarrier()
- constexpr begin of a std::array
- 如何调整 std::vector of Eigen::MatrixXd 的大小
- C++ "error: invalid use of void expression"
- 我看到"use of undeclared identifier"错误,有人可以告诉我如何解决它吗?
- 赛通"Cannot take address of memoryview slice"
- 如何修复此"argument of type incompatible with parameter"错误?
- 矩阵类:"No instance of overloaded function push_back matches the argument list"
- "more than one instance of overloaded function " 标准::p ow " matches the argument list"
- MSVC:"use of class template requires template argument list" STL 容器内
- 'must have an argument of class or enumerated type'到底是什么意思
- "use of class template requires template argument list"错误,即使使用了模板的模板,因此模板类是预期的
- Arduino编译器抛出"invalid type argument of unary *"
- "use of class template requires template argument list"是什么意思?