C++假定错误 C4430 int
C++ error C4430 int assumed
我是C++的新手,C++只有一个小的头文件,里面有一个简单的结构。
PGNFinder.h:
#ifndef PGNFINDER_H
#define PGNFINDER_H
struct Field
{
int Order;
string Name;
//more variables but doesn't matter for now
};
#endif
这给出了下一个错误:
error C2146: syntax error : missing ';' before identifier 'Name'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
当我将其更改为:
struct Field
{
int Order;
std::string Name;
};
它在.exe文件和 .obj 文件中给出错误
error LNK1120: 1 unresolved externals (in the .exe file)
error LNK2019: unresolved external symbol "int __cdecl Convert::stringToInt(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?stringToInt@Convert@@YAHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "private: void __thiscall CAN::calculateMessageLength(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?calculateMessageLength@CAN@@AAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
当我添加时
#include <string>
并改回
string Name;
它给出了与开始时相同的错误。那么为什么头文件无法识别 int 和字符串呢?
感谢您的帮助:)
为了使用 string
作为变量的类型,您需要
- 包括声明它的标头 (
#include <string>
) - 使用完全限定类型(如
std::string
)或通过 using 目录using namespace std;
但请注意,不建议在头文件中使用using
(请参阅 C++ 头文件中的"使用命名空间")
如果您只尝试其中之一,它将不起作用。
但是,您的第二条错误消息似乎指向链接器问题。
因为我倾向于经常使用注释功能。
您的问题是缺少包含,当您包含 string.h 时,您仍然忘记了"字符串类"的 std 命名空间。
所以要么使用using namespace std
(对于初学者的最佳实践,因为大多数东西很可能是 std 的东西)或者在结构中将字符串声明为 std::string。
将其
更改为std::string可以清楚地修复编译器错误。
然后,您有一个与该代码行无关的链接器错误。 您似乎有一个"转换"类,缺少"stringToInt"函数的实现。
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- 由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
- 错误:C4430:缺少类型说明符-假定为int.注意:C++不支持default-int
- 声明 Windows API 结构 (DCB) 的对象 - 错误 C4430:缺少类型说明符 - 假定为 int
- 错误C4430:丢失类型指定词 - 假设INT.注意:C 不支持对我的构造函数的默认设置
- C4430缺少类型的指定词 - 假设INT
- C++假定错误 C4430 int
- CREATESTRUCT错误C4430:缺少类型说明符-假定为int.注意:C++不支持默认的int C:xdc
- 错误 1 错误 C4430:缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- 字符串无法识别?C4430:缺少类型说明符 - 假定为 int
- 模板类:错误 C4430:缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- 错误 C4430、C2146 - 缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- srand(time(NULL)):错误 C4430:缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- 错误C4430:缺少类型说明符-假定为int
- 缺少类型说明符-int假定C4430错误
- 错误c4430缺少类型说明符-假定为int.注意:c++不支持default-int生成器
- C4430错误-缺少类型说明符-假定为int
- C++:"error C4430: missing type specifier - int assumed" 对于构造函数和无效声明
- 使用流模板以避免复制代码会产生"错误 C4430:缺少类型说明符 - 假定为 int"
- 编译器错误C4430:缺少类型说明符-假定为int