编译琐事:错误''没有命名类型
Compilation trivia : error ' ... ' does not name a type
我知道这个问题以前在这里被问过。但我就是做不好。(可能就是其中一次!(。无论如何,这里是一个简单的代码的链接列表
#include <iostream>
typedef struct nodeType {
int data;
struct nodeType *next;
}node;
typedef node *list;
list temp = new nodeType();
temp->data = 5;
我无法编译这段简单的代码!
g++ -g -c list.cpp
error: ‘temp’ does not name a type
typedef struct nodeType {
int data;
struct nodeType *next;
}node;
在C++中没有必要,因为再也不需要复杂的类型说明符了。
struct nodeType
{
int data;
nodeType *next;
};
当然,必须调整相应的CCD_ 1。
list temp = new nodeType();
temp->data = 5;
所有语句都必须进入像main
这样的函数内部,然后应该delete
节点;
int main()
{
list temp = new nodeType; // braces not necessary
temp->data = 5;
delete temp;
}
或者直接将其放入智能指针中。或者更好:编写一个使用RAII创建和销毁节点的类。基本上是CCD_ 4。
相关文章:
- 类没有命名C++代码中的类型错误
- 不完整类型错误(E0409、E0070、E0515)
- 使用具有结构不完整类型错误的模板
- 不命名构造函数和析构函数上的类型错误
- 返回派生类型时出现协变类型错误
- 为什么此构造函数没有给出不完整的类型错误?
- 定义模板化结构的特征时出现不完整的类型错误
- 使用重载构造函数时出现不完整的类型错误
- 为什么我得到表达式必须有类类型错误?
- 输出 [left]=input[i] 行中的 c++ 代码中存在无效的类型错误
- 枚举成员不是类型错误
- 如何修复"ctypes"。参数错误:参数 2:<键入"异常.类型错误">:RaspberryPi 中的错误类型"错误
- 外部 "C" Visual Studio 2015 中的显式类型错误,DLL 测试代码
- 非默认析构函数会导致不完整的类型错误
- 为什么按引用传入会导致绑定引用类型错误
- Objective-C C++ 包装器 类型错误的不完整定义
- 输入类型错误
- 当构造函数的参数类型错误时引发异常
- 命名空间中的'bad_cast' 'std' 未命名类型错误
- C UNWORKOWN类型错误