Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>(I assume that what you posted above is actually a fragment from some header file.)</p> <p>Things like that typically happen when different source files in your program are compiled with different memory-layout-related settings, like class packing and alignment settings. Your header file is included into these different translation units and is interpreted differently because of the discrepancies in memory-layout settings. </p> <p>Once you start passing your <code>Test</code> objects between these translation units, the problem reveals itself. One translation unit creates a <code>Test</code> object with one memory layout, then another translation units reads it or writes into it assuming a totally different memory layout. In your case it is your inline functions that get interpreted differently in each translation unit.</p> <p>If you define your member functions as non-inline ones, they will assume the class memory layout specific to the source file in which they are defined. This will sweep the problem under the carpet and make things "work" (since the access functions are now tied to one memory layout), but nevertheless it is still not a good situation to have. It still can lead to various problems of similar nature down the road.</p> <p>Make sure all source files in your program are compiled with exactly the same class memory layout settings.</p> <p><strong>P.S.</strong> As Fred noted in the comments, the discrepancy in the class memory layout between translation units can be caused by something as prosaic as forgetting to recompile a source file after modifying a header file the source file depends upon.</p> <p>Another "popular" source of such problems is class definitions that depend on preprocessor directives (i.e. class layout "customized" by <code>#ifdef</code>/<code>#endif</code> segments). If you forget to <code>#define</code> something important in some source file that includes your header file, you might end up with different memory layout for the class in that source file.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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