You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Doxygen中让指定子类继承基类成员文档且隐藏基类

解决方案

1. 隐藏基类文档

使用Doxygen的条件注释包裹基类代码,确保基类不会出现在最终生成的文档中:

/// @cond INTERNAL
class Base {
   int value_;
public:
   Base(int value) : value_(value) {}

   /// Returns the value to use
   int getValue() const { return value_; }
};
/// @endcond

@cond INTERNAL与@endcond之间的内容会被Doxygen跳过,不会生成任何基类相关的文档节点。

2. 为子类开启继承成员内联显示

在子类Derived的类级注释中添加局部配置,覆盖全局的INLINE_INHERITED_MEMB = NO,让继承自基类的成员直接内联到子类文档中:

/// This is a class that is in the public user interface
/// @INLINE_INHERITED_MEMB YES
class Derived : public Base {
   int more_data_;

public:
   /// @param value The value that many classes store
   /// @param data The data for this class
   Derived(int value, int data)
      : Base(value), more_data_(data)
   {}

   /// returns the additional data
   int getData() const { return more_data_; }
};

最终效果

生成的文档会呈现出以下状态:

  • 完全没有Base类的相关内容
  • Derived类的成员列表同时包含自身的getData()和继承来的getValue(),所有成员看起来都像是直接定义在Derived类内部,不会标注来源基类

内容的提问来源于stack exchange,提问作者Jay Miller

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 10:16:05