Autosar C++规则3-1-5-类定义中的功能定义

发布于 2025-01-31 12:28:49 字数 580 浏览 1 评论 0原文

我的代码违反了以下AUTOSAR规则:

规则3-1-5:

仅在

时才将函数定义放置在类定义中。
  1. 该函数旨在分配
  2. 它是成员函数模板
  3. 它是类模板的成员函数。

ah:

class A {
  public:
    void stop();
  private:
    bool x = false;
};

a.cpp:

void A::stop() {     // violates AUTOSAR 3-1-5
  x = false;
}

我尝试使用关键字inline来定义该函数,但这并不能解决问题。

违规仅发生仅由仅由一条线组成的函数。如果在不存在类的标题文件中定义函数(例如,在结构中),也会发生此问题。

有人知道如何解决吗?

My code violates the following AUTOSAR rule:

Rule 3-1-5:

A function definition shall only be placed in a class definition if

  1. the function is intended to be inlined
  2. it is a member function template
  3. it is a member function of a class template.

A.h:

class A {
  public:
    void stop();
  private:
    bool x = false;
};

A.cpp:

void A::stop() {     // violates AUTOSAR 3-1-5
  x = false;
}

I tried defining the function with the keyword inline, but that didn't solve the problem.

The violation occurs only with functions that consist of only one line. This problem also occurs if the function is defined in a header file where no class exists (e.g. in a struct).

Does anyone have an idea how I can solve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文