Note that there are some explanatory texts on larger screens.

plurals
  1. POconstructor returns mistake, dynamic memory c++
    primarykey
    data
    text
    <pre><code>#pragma once # include &lt;iostream&gt; # include &lt;string&gt; # include &lt;cstring&gt; using namespace std; const int err=404; class longMath{ protected: char* str; int size; protected: //void create(int len); public: inline longMath(); inline longMath(longMath &amp;a); inline longMath(char* s); inline longMath(string &amp;s); ~longMath(){delete [] str;} void print(); }; //-------------------------------------------------------------// longMath::longMath(){size=0;} longMath::longMath(longMath &amp;a){ str = new char [a.size]; strncpy(str,a.str,a.size); size= a.size; } longMath::longMath(char* s){ size = (sizeof s)/(sizeof s[0]); str = new char [size+1]; strncpy_s(str,size+1,s,size); } void longMath::print(){ for (int i=0;i&lt;size;i++){ cout&lt;&lt;*(str+i); } cout&lt;&lt;endl; } longMath::longMath(string &amp;s){ str = new char [s.length()]; for (int i=0;i&lt;size;i++){ *(str+i)=s[i]; } size = s.length(); } longMath longMath::operator= (const longMath &amp;a){//оператор присвоения if (this==&amp;a) return *this; delete [] str; str = new char [a.size]; strncpy(str,a.str,a.size); size = a.size; return *this; } //----------additional function--------------------// int switcher(char &amp;c){ switch (c){ case '1': return 1; break; case '2': return 2; break; case '3': return 3; break; case '4': return 4; break; case '5': return 5; break; case '6': return 6; break; case '7': return 7; break; case '8': return 8; break; case '9': return 9; break; case '0': return 0; break; default: return err; } } </code></pre> <p>And another main file </p> <pre><code># include &lt;iostream&gt; # include "longMath.h" using namespace std; int main(){ char* s("regw"); longMath h,n(s); n.print(); system("PAUSE"); return 0; } </code></pre> <p>This program doesn't want to compile, it returns exception in <code>0x0f8657aa (msvcr100d.dll)</code></p> <p>Help me with this please. Program seems like not too complicated. There is a problem in constructor, initialized with <code>char*</code>.</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.
    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