File tree Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -860,27 +860,40 @@ your private interface remains private and undisturbed by outsiders.
860860 It's okay to put extra implementation methods in a public class itself. Just
861861 make them private (or protected) and all is well.
862862
863- Use Namespace Qualifiers to Implement Previously Declared Functions
864- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
863+ Use Namespace Qualifiers to Define Previously Declared Symbols
864+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
865865
866- When providing an out-of-line implementation of a function in a source file, do
867- not open namespace blocks in the source file. Instead, use namespace qualifiers
868- to help ensure that your definition matches an existing declaration. Do this:
866+ When providing an out-of-line definition for various symbols (variables,
867+ functions, opaque classes) in a source file, do not open namespace blocks in the
868+ source file. Instead, use namespace qualifiers to help ensure that your
869+ definition matches an existing declaration. Do this:
869870
870871.. code-block :: c++
871872
872873 // Foo.h
873874 namespace llvm {
875+ extern int FooVal;
874876 int foo(const char *s);
875- }
877+
878+ namespace detail {
879+ class FooImpl;
880+ } // namespace detail
881+ } // namespace llvm
876882
877883 // Foo.cpp
878884 #include "Foo.h"
879885 using namespace llvm;
886+
887+ int llvm::FooVal;
888+
880889 int llvm::foo(const char *s) {
881890 // ...
882891 }
883892
893+ class detail::FooImpl {
894+ // ...
895+ }
896+
884897Doing this helps to avoid bugs where the definition does not match the
885898declaration from the header. For example, the following C++ code defines a new
886899overload of ``llvm::foo `` instead of providing a definition for the existing
You can’t perform that action at this time.
0 commit comments