Note that there are some explanatory texts on larger screens.

plurals
  1. POProgram Crashes While Setting Data in Array
    primarykey
    data
    text
    <p>I'm working on a project and every time I go to set example[4].m_dArray[3], the program crashes. I can set the value of every other variable up until I get to example[4].m_dArray[3]. Any help would be appreciated!</p> <p>Prog1Class.h:</p> <pre><code>#include "Prog1Struct.h" #pragma once #include &lt;iostream&gt; #include &lt;string.h&gt; using namespace std; class Prog1Class { private: Prog1Struct example[4]; public: Prog1Class(); ~Prog1Class (); void setStructData(); void getStructData(); void ptrFunction(); void refFunction(); void printStruct(); void printData(); }; </code></pre> <p>Prog1Struct.h:</p> <pre><code> #pragma once #include &lt;string.h&gt; struct Prog1Struct { int m_iVal; double m_dArray[4]; char m_sLine[80]; }; </code></pre> <p>Prog1Class.cpp:</p> <pre><code>#include "Prog1Class.h" #include "Prog1Struct.h" #include &lt;iostream&gt; #include &lt;string.h&gt; using namespace std; Prog1Class::Prog1Class() { } Prog1Class::~Prog1Class() { delete &amp;example[4]; } int main() { Prog1Class *aClass = new Prog1Class(); aClass-&gt;setStructData(); aClass-&gt;printData(); return 0; } void Prog1Class::setStructData() { for(int i=0;i&lt;5;i++) { cout &lt;&lt; "Enter an integer: "; cin &gt;&gt; example[i].m_iVal; for(int j=0;j&lt;5;j++) { cout &lt;&lt; endl &lt;&lt; "Enter a double: "; cin &gt;&gt; example[i].m_dArray[j]; } cout &lt;&lt; endl &lt;&lt; "Enter a string: "; cin.ignore(256,'\n'); cin.getline(example[i].m_sLine, 80, '\n'); cout &lt;&lt; endl; } } void Prog1Class::getStructData() { } void Prog1Class::printData() { for(int i=0;i&lt;5;i++) { cout &lt;&lt; example[i].m_iVal; for(int j=0;j&lt;5;j++) { cout &lt;&lt; example[i].m_dArray[j]; } cout &lt;&lt; example[i].m_sLine; } } </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.
 

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