c++;:循环处的TypeError-但在循环工作之前,它-(modified)LinkedListClass将迭代 我有一个C++项目用于ARDUNO,我不会使用它的STD::包也有原因。所以我四处寻找Arduino的LinkedList类,并在github上创建了一个类:
我想迭代列表中的所有。 为此,我有以下代码:c++;:循环处的TypeError-但在循环工作之前,它-(modified)LinkedListClass将迭代 我有一个C++项目用于ARDUNO,我不会使用它的STD::包也有原因。所以我四处寻找Arduino的LinkedList类,并在github上创建了一个类:,c++,loops,pointers,linked-list,C++,Loops,Pointers,Linked List,我想迭代列表中的所有。 为此,我有以下代码: uint8_t memory::write_data(uint8_t id) { // here is all ok -> working, but not in the loop that follows. uint16_t temp_size = (uint16_t) blocks->get(id); uint8_t blocks = (uint8_t) (temp_size / (uint8_t)255);
uint8_t memory::write_data(uint8_t id) {
// here is all ok -> working, but not in the loop that follows.
uint16_t temp_size = (uint16_t) blocks->get(id);
uint8_t blocks = (uint8_t) (temp_size / (uint8_t)255); // => 256 = 1byte - 1 => (0-255) => range (1-256);
if (temp_size < 255) blocks++;
uint16_t pointer = 0; // With pointer means the pointer (in byte) for the "memory(eeprom)" location
for (uint8_t i=0; i<id; i++) {
Serial.print("Index:");
Serial.println(blocks.get(i)); // -> instand of int is going to go error
// !! ERROR: request for member 'get' in 'blocks', which is of non-class type 'uint8_t {aka unsigned char}'
//pointer += i;
}
Serial.print("ALL:");
Serial.println(pointer);
}
uint8\u t内存::写入数据(uint8\u t id){
//这里是一切正常->工作,但不是在随后的循环中。
uint16_t temp_size=(uint16_t)块->获取(id);
uint8_t块=(uint8_t)(临时大小/(uint8_t)255);//=>256=1字节-1=>(0-255)=>范围(1-256);
如果(温度大小<255)块++;
uint16\u t pointer=0;//With pointer表示“内存(eeprom)”位置的指针(字节)
对于(uint8_t i=0;int的i实例将出错
//!!错误:请求“blocks”中的成员“get”,该成员为非类类型“uint8_t{aka unsigned char}”
//指针+=i;
}
序列号。打印(“全部:”);
Serial.println(指针);
}
错误:请求“blocks”中的成员“get”,该成员属于非类类型“uint8_t{aka unsigned char}”
此时库中的代码为:
template<typename E, typename T>
T LinkedList<E, T>::get(E index){
ListNode<T> *tmp = getNode(index);
return (tmp ? tmp->data : T());
}
模板
T LinkedList::get(E索引){
ListNode*tmp=getNode(索引);
返回(tmp?tmp->data:T());
}
而且
template<typename E, typename T>
ListNode<T>* LinkedList<E, T>::getNode(E index){
int _pos = 0;
ListNode<T>* current = root;
// Check if the node trying to get is
// immediatly AFTER the previous got one
if(isCached && lastIndexGot <= index){
_pos = lastIndexGot;
current = lastNodeGot;
}
while(_pos < index && current){
current = current->next;
_pos++;
}
// Check if the object index got is the same as the required
if(_pos == index){
isCached = true;
lastIndexGot = index;
lastNodeGot = current;
return current;
}
return false;
}
模板
ListNode*LinkedList::getNode(E索引){
int _pos=0;
ListNode*当前=根;
//检查尝试获取的节点是否为
//就在上一个得到一个之后
如果(isCached&&lastIndexGot next;
_pos++;
}
//检查获取的对象索引是否与所需的相同
如果(_pos==索引){
isCached=真;
lastIndexGot=指数;
lastNodeGot=电流;
回流;
}
返回false;
}
LinkedList的定义如下:
LinkedList <uint8_t, uint16_t> *blocks = new LinkedList<uint8_t, uint16_t>();
LinkedList*blocks=newLinkedList();
我已尝试找到解决此问题的方法,但我做不到。有人能告诉我问题所在吗?谢谢。
uint8\u t
是简单的值,不是类。它没有.get()
方法
你只要写就行了
Serial.println(块[i]);
如果重写该行
uint8_t blocks = (uint8_t) (temp_size / (uint8_t)255);
与
谢谢。我太蠢了。我已经用uint8_t块覆盖了LinkedList块,我还没有看到这个。我知道还不能100%确定来自的指针。
uint8_t* blocks = (uint8_t*) (temp_size / (uint8_t)255);