Rule #3-2-3 and Forward Declarations?

Moderators: david ward, misra cpp

gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

Rule #3-2-3 and Forward Declarations?

Postby gs » Wed Aug 18, 2010 8:05 pm

Does rule #3-2-3 prohibit the use of forward declarations in separate files? For example, if a file, a.h, contained "class B;" and another file, c.h, #include'd a.h and contained a definition for class D which contained "friend class B;", would the rule permit such?

ggoulas
Posts: 5
Joined: Tue Jun 09, 2009 1:43 pm
Company: The MathWorks

Re: Rule #3-2-3 and Forward Declarations?

Postby ggoulas » Thu Sep 17, 2015 3:05 pm

I am interested by the answer to this question. Should forward declaration such as

class a_class;

be allowed by rule 3-2-3 anywhere in source files?
Could misra reply to this please?

misra cpp
Posts: 145
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: Rule #3-2-3 and Forward Declarations?

Postby misra cpp » Tue Oct 11, 2016 10:32 am

This rule does not preclude the use of friend or forward reference statements, but these must be in a separate header file.

A future edition may reconsider this point
Posted by and on behalf of
the MISRA C++ Working Group

gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

Re: Rule #3-2-3 and Forward Declarations?

Postby gs » Fri Mar 24, 2017 4:19 pm

I don't understand. Are you saying the "one and only one file" requirement does not apply to friend declarations and forward references?

misra cpp
Posts: 145
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: Rule #3-2-3 and Forward Declarations?

Postby misra cpp » Mon Jul 10, 2017 11:02 am

This rule does not preclude the use of friend or forward reference statements, but these must be in a separate header file.

A future edition may reconsider this point

The second question, your examples are compliant - the objective is to ensure that class definitions are only made in one file (and not repeated in multiple translation units)"
Posted by and on behalf of
the MISRA C++ Working Group


Return to “6.3 Basic concepts (C++)”

Who is online

Users browsing this forum: No registered users and 5 guests