C ++链表奇怪的编译器错误
c++ linked list strange compiler-error
我正在尝试使用以下代码在C++中创建链表
int main ()
{
return 0;
}
class LList
{
private:
struct node
{
int value;
node *follower; // node definitely is a node
};
node m_list;
int m_length;
public:
LList ();
void insert (int index, int value);
int get_length () const { return m_length; }
};
LList::LList ()
{
m_length = 0;
m_list.follower = 0;
}
void LList::insert (int index, int value)
{
node *cur_node = &m_list;
for (int count=0; count<index; count++)
{
cur_node = cur_node.follower; // << this line fails
}
}
(这不是我的原始代码,所以请忽略任何不合逻辑的东西,糟糕的命名......
使用 g++ 编译它会导致以下编译器错误
main.cpp: 在成员函数 'void LList::insert(int, int(' 中: 主.cpp:33:29:错误:在"cur_node"中请求成员"关注者", 非类类型为"LList::node*">
然而,"追随者"似乎是一个节点!?
笔记:-我正在使用命令使用 g++ 4.6.2
g++ main.cpp -Wall -g -o my_program
-在软呢帽 16 64 位机器上工作
提前感谢!
指针可通过->
访问:
cur_node = cur_node->follower;
node *cur_node = &m_list;
cur_node
是node
指针
for (int count=0; count<index; count++)
{
cur_node = cur_node->follower;
}
应该工作
相关文章:
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++,我收到一个无法理解的编译器错误
- 我收到同义重复编译器错误。我应该如何修复"类型"X"的参数与类型"X"的参数不兼容?
- 重载方法的方式会在使用临时调用时生成编译器错误
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- 编译器错误:destuctor 的更宽松的抛出说明符
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- C++ G++ 编译器 - 错误:隐式声明的定义
- 这个失败的测试是将零添加到空指针未定义的行为、编译器错误还是其他什么?
- 模板模板参数和模板别名:编译器错误?
- C++ 编译器错误:P1LinkedList.cpp:145:错误:重载的"to_string(int&)"调用不明确
- 在gcc中意外调用了Const重载.编译器错误或兼容性修复程序
- C1001内部编译器错误是由于矢量初始化(如数组)引起的
- 编译器错误(英特尔并行工作室 2019 与 Visual Studio 社区 2019)
- 如何在C++中克服此 C4430 编译器错误?
- 尝试使用 WinBGI 显示文本时出现编译器错误
- 使用typedef'ed返回类型声明友元函数时出现编译器错误
- 如何在类模板的成员函数中正确调用函数对象?正在生成 Visual Studio 编译器错误 C2440
- C++自定义分配器大小参数作为模板参数会引发编译器错误