Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's no specific mechanism for doing this directly in the current C++, but there are several ways you can achieve something like it at the cost of some boiler-plate work:</p> <p>Method 1:</p> <pre><code>// foo.h class Foo { private: // stuff public: // stuff private: // All this crap is private. Pretend like I didn't expose it. // yeah, I know, you have to compile it, and it probably adds // dependencies you don't want to #include, like &lt;string&gt; // or boost, but suck it up, cupcake. Stroustrup hates life. void internalHelper(std::string&amp;, std::vector&amp;, boost::everything&amp;); }; </code></pre> <p>Method 2:</p> <pre><code>// foo.h class Foo { private: // stuff public: // stuff }; // fooimpl.h // Internal file, do not export with the API. class FooImpl : public Foo { private: // stuff public: // stuff // So yeah, you have to go thru a cast and an extra include // if you want to access this. Suck it up, cupcake. void internalHelper(std::string&amp;, std::vector&amp;, boost::everything&amp;); }; </code></pre> <p>Method 3:</p> <pre><code>// foo.h class Foo { private: // stuff public: // stuff // For the private api: this is the worst approach, since it // exposes stuff and forces include/cruft on consumers. friend void foo_internalHelper(std::string&amp;, std::vector&amp;, boost::everything&amp;); }; // foo.cpp // don't make it static or anyone can make their own as a way to // back door into our class. void foo_internalHelper(...); </code></pre> <p>Method 4:</p> <pre><code>// foo.h class Foo { private: // stuff public: // stuff // No dependencies, but nothing stops an end-user from creating // a FooPrivate themselves... friend class FooPrivate; }; // foo1.cpp class FooPrivate { public: void fooInternalHelper(Foo* f) { f-&gt;m_privateInternalYouCantSeeMe = "Oh, but I can"; } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload