c++ - 由于 `using` 导致命名空间不匹配导致 Doxygen 与 header 签名不同时无法解析 cpp 文件中的方法签名

标签 c++ namespaces doxygen

我有以下头文件:

#ifndef LOGIN_STATEMACHINE_EXCEPTION_HPP_
#define LOGIN_STATEMACHINE_EXCEPTION_HPP_

#include "LoginLib/StateMachine/Global.hpp"
#include "LoginLib/Common/Exception.hpp"
#include <string_view>
#include <string>

namespace LoginLib {
namespace StateMachine {

class Exception : public Common::Exception {
public:

  LOGINLIB_STATEMACHINE_LIB Exception(std::string_view message);
  virtual ~Exception() = default;
};

} // namespace StateMachine
} // namespace LoginLib

#endif // !LOGIN_STATEMACHINE_EXCEPTION_HPP_

///////////////////////////////////////////////////////////////////////////////
// DOCUMENTATION                                                             //
///////////////////////////////////////////////////////////////////////////////

/**
 * @class LoginLib::StateMachine::Exception
 *
 * @brief Exception class for state machine library
 *
 * This is the exception that's raised when the state machine library launches
 * an exception.
 */

以及以下 cpp 文件:
#include "LoginLib/StateMachine/Exception.hpp"

namespace LoginLib {
namespace StateMachine {

///////////////////////////////////////////////////////////////////////////////
// USING SECTION                                                             //
///////////////////////////////////////////////////////////////////////////////

using std::string_view;

///////////////////////////////////////////////////////////////////////////////
// PUBLIC SECTION                                                            //
///////////////////////////////////////////////////////////////////////////////

/**
 * @brief Message constructor.
 *
 * This constructor allows to define a message that must be associated with the
 * exception.
 *
 * @param[in] message Message that must be set.
 */
Exception::Exception(string_view message) :
  Common::Exception(std::string(message)) {
}

} // namespace StateMachine
} // namespace LoginLib

如果我尝试构建 doxygen 文档,我会收到以下警告(我将其视为错误):
H:/path/Exception.cpp:24: error: no matching class member found for
  LoginLib::StateMachine::Exception::Exception(string_view message)
Possible candidates:
  LOGINLIB_COMMON_LIB LoginLib::Common::Exception::Exception(const std::string &message)
  LOGINLIB_STATEMACHINE_LIB LoginLib::StateMachine::Exception::Exception(std::string_view message)
 (warning treated as error, aborting now)

如果不使用 string_view,错误就会消失我在 cpp 构造函数方法中的签名 std::string_view :
#include "LoginLib/StateMachine/Exception.hpp"

namespace LoginLib {
namespace StateMachine {

///////////////////////////////////////////////////////////////////////////////
// USING SECTION                                                             //
///////////////////////////////////////////////////////////////////////////////

using std::string_view;

///////////////////////////////////////////////////////////////////////////////
// PUBLIC SECTION                                                            //
///////////////////////////////////////////////////////////////////////////////

/**
 * @brief Message constructor.
 *
 * This constructor allows to define a message that must be associated with the
 * exception.
 *
 * @param[in] message Message that must be set.
 */
Exception::Exception(std::string_view message) :
  Common::Exception(std::string(message)) {
}

} // namespace StateMachine
} // namespace LoginLib

显然这不允许我定义 using语句,我需要重写所有代码,以便将命名空间放在所有方法和函数参数中,这是我需要避免的事情。我怎么能告诉 doxygen string_viewstd::string_view ,显然对于我以相同方式处理的所有其他类?

最佳答案

在 1.8.15 版中 string_view尚不支持。

在 1.8.17 版中 string_view支持并解决问题。
(引用提交:使用更多类扩展内置 STL 支持(https://github.com/doxygen/doxygen/commit/742927e23a728fffe53e7bfd1d220f7df4c6f552)

关于c++ - 由于 `using` 导致命名空间不匹配导致 Doxygen 与 header 签名不同时无法解析 cpp 文件中的方法签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60756297/

相关文章:

php - 如何从在 PHP 中使用自动加载加载的类中捕获异常?

php - Yii2 子目录的解决方法?

visual-studio - Doxygen 是否支持 C++/CX 语法?

c++ - 如何在 Resharper 中更改 doxygen 格式化样式?

objective-c - 如何在 Xcode 中使用 Doxygen?

c++ - Opengl macOS 失败

c++ - 为什么我不能多重声明一个类

c++ - shared_ptr 分配 : order of reference counting

C++:全局变量与局部变量。用什么?

spring - 在 Spring 中嵌套自定义标签