不能返回指向结构体的指针
C++ : Cannot return a pointer to a struct
我试图有一个函数返回一个指向链表中最小单元格的指针,其中单元格是一个结构体。这个函数给了我错误,说函数缺少类型说明符。如有任何帮助,不胜感激。
. h文件private:
// TODO: Fill this in with the implementation of your doubly-linked list
// priority queue. You can add any fields, types, or methods that you
// wish.
struct Cell {
string value;
Cell * next;
Cell * prev;
};
int count;
Cell * root;
void clear();
Cell * getSmallestCell();
. cpp文件Cell * DoublyLinkedListPriorityQueue::getSmallestCell() {
Cell * smallest = root;
for (Cell * i = root; i != NULL; i = i->next) {
if (i->value < smallest->value) {
smallest = i;
}
}
return smallest;
}
代替
Cell* DoublyLinkedListPriorityQueue::getSmallestCell()
应该是
DoublyLinkedListPriorityQueue::Cell* DoublyLinkedListPriorityQueue::getSmallestCell()
或(c++ 11起)
auto DoublyLinkedListPriorityQueue::getSmallestCell() -> Cell *
作为Cell
是DoublyLinkedListPriorityQueue
的内类型
相关文章:
- C++ 使用成员函数返回结构体指针属性的值
- 在使用结构体和用函数填充其变量(使用指针)时遇到问题
- 如何使用结构体作为接口从函数返回指向数组的指针
- 如何在结构体中传递指向CURL的指针到向量
- 使用c++中从IDA导出的带有指针的结构体
- 设置两个结构体相等后,指针为NULL
- 结构体中的指针
- 指向结构体的向量指针错误
- 指向结构体的Void *指针
- 返回指向类定义的结构体的指针,多个作用域操作符
- 带有指针的结构体向量
- 你能解释一下指针和递归结构体吗?
- c语言中具有指针数组的结构体
- c++用数组、结构体和指针排序
- 初始化没有指针的结构体
- 如何在不激怒编译器的情况下传递指向结构体的指针?
- 如何释放一个结构体的内存,每次循环迭代的指针
- 如何根据结构体的字段之一对结构指针列表进行排序?
- 从c#调用c++函数-结构体,指针,函数指针
- /a.检测到Glibc.out: munmap_chunk():无效指针- c++结构体的动态数组