c++宏给出了C4430错误:缺少类型说明符
C++ macro gives C4430 error: Missing type specifier
我遵循Google的c++风格指南,该指南建议:对于类,应该添加宏
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName(const TypeName&);
void operator=(const TypeName&)
class MyClass {
...
DISALLOW_COPY_AND_ASSIGN(MyClass);
};
#undef DISALLOW_COPY_AND_ASSIGN
我将这个宏添加到项目中的许多类中。当我编译时,我得到错误:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
任何想法?
...
部分错误。此外,最好将您的复制和传递操作符delete
,而不是仅仅隐藏它们
class Foo
{
public:
Foo(Foo&) = delete;
Foo& operator=(const Foo&) = delete;
}
注意delete
是c++11特性
我相信你在这里少了一个分号:
void operator=(const TypeName&)
既然这个被否决了,我就证明给你看。
这是你的原始代码(与...
删除和添加一些其他的东西,使其实际编译你的类),未能编译:
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName(const TypeName&);
void operator=(const TypeName&)
class MyClass {
public: MyClass()
:
mN (42)
{
}
private:
int mN;
DISALLOW_COPY_AND_ASSIGN(MyClass)
long mL;
};
#undef DISALLOW_COPY_AND_ASSIGN
int main()
{
MyClass c;
}
在c++ 4.8下,编译器报错:
jdibling@hurricane /home/jdibling/dev/hacks $ g++ main.cpp
main.cpp:3:33: error: expected ‘;’ at end of member declaration
void operator=(const TypeName&)
^
main.cpp:14:1: note: in expansion of macro ‘DISALLOW_COPY_AND_ASSIGN’
DISALLOW_COPY_AND_ASSIGN(MyClass)
^
如果我们编辑宏定义以包含分号:
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName(const TypeName&);
void operator=(const TypeName&);
它编译干净:
jdibling@hurricane /home/jdibling/dev/hacks $ g++ main.cpp
jdibling@hurricane /home/jdibling/dev/hacks $
相关文章:
- 缺少类型说明符,显式类型为"缺少错误"
- 与 tesseract::TessBaseApi() 相关的 Tesseract-OCR 出错(预期的类型说明符)
- 为什么转换函数声明不需要至少一个定义类型说明符
- C++需要所有声明的类型说明符和预期的非限定 id(需要调试帮助)
- printf 数据类型说明符复杂问题
- C++错误:"class name"之前的预期类型说明符
- 缺少类型说明符和另一个问题
- 缺少类型说明符 - 假定为 int.注意 c++ 不支持 default-int
- 错误:C4430:缺少类型说明符-假定为int.注意:C++不支持default-int
- 在C++中出现错误之前,无效使用了不完整的类型和所需的类型说明符
- 缺少类型说明符 - int 假定 声明静态成员后出错
- 不能在类型说明符中定义联合
- 没有带有字符串数组的存储类或类型说明符
- 警告:函数使用不带尾随返回类型的'auto'类型说明符
- 仅为某些模板专用化定义转换运算符:预期类型/预期类型说明符
- 在 C++ 中出现unique_ptr错误之前的预期类型说明符
- 有没有办法将类型说明符存储在变量中
- C 期望类对象的类型说明符
- 是无符号的int"简单类型说明符"
- 在 vscode 上编译错误.类型说明符是 C++11 扩展