MISRA Discussion Forums
Rule #3-2-3 and Forward Declarations? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19)
+---- Forum: 6.3 Basic concepts (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=132)
+---- Thread: Rule #3-2-3 and Forward Declarations? (/showthread.php?tid=766)



Rule #3-2-3 and Forward Declarations? - gs - 18-08-2010

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?


Re: Rule #3-2-3 and Forward Declarations? - ggoulas - 17-09-2015

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?


Re: Rule #3-2-3 and Forward Declarations? - misra cpp - 11-10-2016

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


Re: Rule #3-2-3 and Forward Declarations? - gs - 24-03-2017

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


Re: Rule #3-2-3 and Forward Declarations? - misra cpp - 10-07-2017

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)"