Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This code is a mess and RnR and others suggested is not advisable. But it works for what i want it to do:</p> <pre><code>#include &lt;iostream&gt; using namespace std; struct pString { /* No Member Variables, the data is the object */ /* This class cannot be extended &amp; will destroy a vtable */ public: pString * pString::operator=(const char *); }; pString&amp; operator+(pString&amp; first, const char *sec) { int lenFirst; int lenSec = strlen(sec); void * newBuff = NULL; if (&amp;first == NULL) { cout &lt;&lt; "NULL" &lt;&lt; endl; lenFirst = 0; newBuff = malloc(sizeof(pString)+lenFirst+lenSec+1); } else { lenFirst = strlen((char*)&amp;first); newBuff= (pString*)realloc(&amp;first, lenFirst+lenSec+1); } if (newBuff == NULL) { cout &lt;&lt; "Realloc Failed"&lt;&lt; endl; free(&amp;first); exit(0); } memcpy((char*)newBuff+lenFirst, sec, lenSec); *((char*)newBuff+lenFirst+lenSec) = '\0'; cout &lt;&lt; "newBuff: " &lt;&lt; (char*)newBuff &lt;&lt; endl; return *(pString*)newBuff; }; pString * pString::operator=(const char * buff) { cout &lt;&lt; "Address of this: " &lt;&lt; (uint32_t) this &lt;&lt; endl; char *newPoint = (char *)realloc(this, strlen(buff)+200); memcpy(newPoint, buff, strlen(buff)); *((char*)newPoint+strlen(buff)) = '\0'; cout &lt;&lt; "Address of this After: " &lt;&lt; (uint32_t) newPoint &lt;&lt; endl; return (pString*)newPoint; }; int main() { /* This doesn't work that well, there is something going wrong here, but it's just a proof of concept */ cout &lt;&lt; "Sizeof: " &lt;&lt; sizeof(pString) &lt;&lt; endl; pString * myString = NULL; //myString = (pString*)malloc(1); myString = *myString = "testing"; pString&amp; ref = *myString; //cout &lt;&lt; "Address of myString: " &lt;&lt; myString &lt;&lt; endl; ref = ref + "test"; ref = ref + "sortofworks" + "another" + "anothers"; printf("FinalString:'%s'", myString); } </code></pre>
 

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