C++中类重定义错误

出错原因:.h文件互相包含所导致的

方法1:

参考:http://www.cppblog.com/SmartPtr/archive/2007/07/05/27550.aspx

在出错的类前加#pragma once指示符,保证本文本只能被编译一次

#pragma once
class Type
{  

};

方法2:

参考:http://blog.sina.com.cn/s/blog_a459dcf50101e82r.html

在出现重定义错误的头文件加上:

#ifndef FileName_H_

扫描二维码关注公众号,回复: 1691701 查看本文章

#define FileName_H_   

....(头文件内容)

#endif

猜你喜欢

转载自blog.csdn.net/summer00072/article/details/80753735