Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Header file that declares a class and methods but not members?
    primarykey
    data
    text
    <p>Is it possible to make a C++ header file (.h) that declares a class, and its public methods, but does not define the private members in that class? I found a <a href="http://www.eventhelix.com/realtimemantra/HeaderFileIncludePatterns.htm" rel="noreferrer">few pages</a> that say you should declare the class and all its members in the header file, then define the methods separately in you cpp file. I ask because I want to have a class that is defined in a Win32 DLL, and I want it to be properly encapsulated: the internal implementation of that class might change, including its members, but these changes should not affect code that uses the class.</p> <p>I guess that if I had this, then it would make it impossible for the compiler to know the size of my objects ahead of time. But that should be fine, as long as the compiler is smart enough to use the constructor and just pass around pointers to the location in memory where my object is stored, and never let me run "sizeof(MyClass)".</p> <p><strong>Update:</strong> Thanks to everyone who answered! It seems like the pimpl idiom is a good way to achieve what I was talking about. I'm going to do something similar:</p> <p>My Win32 DLL file will have a bunch of separate functions like this:</p> <pre><code>void * __stdcall DogCreate(); int __stdcall DogGetWeight(void * this); void __stdcall DogSetWeight(void * this, int weight); </code></pre> <p>This is the typical way the Microsoft writes their DLL files so I think there is probably good reason for it.</p> <p>But I want to take advantage of the nice syntax C++ has for classes, so I'll write a wrapper class to wrap up all of these functions. It will have one member, which will be "void * pimpl". This wrapper class will be so simple that I might as well just declare it AND define it in the header file. But this wrapper class really has no purposes other than making the C++ code look pretty as far as I can tell.</p>
    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.
 

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