头文件包括彼此

 手机用户2502873453_987 发布于 2023-02-12 14:04

我有两个头文件.decimal.h和integer.h,每个都包含它们各自的类.我想写这样的东西.

//integer.h
#ifndef INTEGER_H
#define INTEGER_H
#include "decimal.h"
class Integer
{
     ...
     operator Decimal();
}
#endif

//decimal.h
#ifndef DECIMAL_H
#define DECIMAL_H
#include "integer.h"
class Decimal
{
     ...
     operator Integer();
}
#endif

给我带来麻烦的是,因为它们包含了它,所以它在Visual Studio中表现得很奇怪并且产生奇怪的编译器错误.有没有办法解决?

1 个回答
  • 也许你只想要一个前瞻宣言?

    // In Integer.h
    class Decimal;
    class Integer
    {
         ...
         operator Decimal();
    };
    

    (顺便说一句,你错过了代码中的最后一个分号.)

    2023-02-12 14:24 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有