如何修复这些错误:C2146 和 C4430(在 C++ 中)
How to fix these errors: C2146 & C4430 (in c++)
所以,我的老师给了全班这个代码,但我在运行它时遇到了问题。 我得到的错误是C2146和C4430。我尝试通过将包含添加到头文件来弄乱,但我仍然不确定问题是什么。
我已经注释了下面的代码,其中错误由编译器指示。
助理H文件
template<class T> class assoc {
public:
struct pair {
string key; //error C2146: syntax error: missing ';' before identifier 'key'
T value;
pair *next;
pair() : key(), value(), next(NULL) {}
pair( const string& key, T value, pair* next = NULL ) //error c4430: missing type specifier - int assumed. Note: c++ does not suport default - int
: key(key), value(value), next(next) {}
};
private:
pair * table;
}
未定义string
类型。您需要从std
命名空间导入它:
#include <string>
using std::string;
当然,您也可以使用using namespace std;
从命名空间导入所有内容,但这通常是一个坏主意 - 对于不像string
那样普遍的东西,最好使用限定名称(例如std::pair
)。您的代码实际上是一个很好的例子,您的pair
using namespace std
会与std
中的代码发生冲突。
相关文章:
- 如何在C++中克服此 C4430 编译器错误?
- 由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
- 错误:C4430:缺少类型说明符-假定为int.注意:C++不支持default-int
- Qt <winInet.h> 在构建时输出许多 C4430 和 C2146 错误
- 声明 Windows API 结构 (DCB) 的对象 - 错误 C4430:缺少类型说明符 - 假定为 int
- 错误C4430:丢失类型指定词 - 假设INT.注意:C 不支持对我的构造函数的默认设置
- C++ and visual studio 2017: error c4430
- C4430缺少类型的指定词 - 假设INT
- 简单代码给出C 错误C4430和C2143
- 如何修复这些错误:C2146 和 C4430(在 C++ 中)
- C++假定错误 C4430 int
- 错误 C2144 和错误 C4430 在同一行上
- 尝试双重多集对象后出现 C4430 错误
- 模板类中函数的错误 C4430、C2143 和 C2244
- 外部"C"和错误 C4430
- CREATESTRUCT错误C4430:缺少类型说明符-假定为int.注意:C++不支持默认的int C:xdc
- C++编译错误C4430
- C4430 and C2146 Visual Studio errors
- 错误 1 错误 C4430:缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- 字符串无法识别?C4430:缺少类型说明符 - 假定为 int