Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does putting a string in a struct cause a crash?
    primarykey
    data
    text
    <p>I have a structure that contains, among other things, a couple of strings.</p> <pre><code>struct item { string item_name; int item_property_1; double item_property_2; } </code></pre> <p>Later I initialize them:</p> <pre><code>item item1; item1.item_name = "Name of Item"; item1.item_property_1 = 5; item1.item_property_2 = 10.0; </code></pre> <p>If I comment out the line assigning the string, it runs fine. With the string assignment, it crashes. I have no idea why.</p> <p>I have now commented out the contents of every other function trying to track down what could be causing the suggested corruption, and it still crashes. I'm down to one struct with a few strings and numbers, and if I assign a value to any of the strings it crashes.</p> <p>What could cause that corruption?</p> <p><em>edit</em> Adding in, by request, the smallest amount of real code that causes a crash. Commented out sections are omitted.</p> <pre><code>struct player_c { string advClass; int role; }; player_c shadow; Shadow::Shadow(QWidget *parent) : QMainWindow(parent), ui(new Ui::Shadow) { ui-&gt;setupUi(this); shadow.advClass = " "; shadow.role = 1; } </code></pre> <p>That's all that's left. I only included the int to test and verify that assigning it a value worked fine, and so long as the string is commented out it does. Any use of strings in the struct causes a crash.</p> <p>I don't NEED them there. I'm not currently using those strings, I put them in the struct because I intend to use them later, but I can accomplish the same purpose without them. Right now I just want to understand why.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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