Hi all, I'm writing an expression parser using Baur and Zamelzon algorithm, but it seems that it can't handle unary minuses correctly :( What shall I do, does anybody know some algorithm that can parse unary minuses correctly ? Don't offer reverse notation, it has the same problem :(
Sheff
Posts
-
Expression parser. Unary minus problems :( -
operator+, problems...Oh, thank's a lot, you helped a lot. I'm writing an interpreter and I needed a specialized string class of my own, and that's the first time I hear about COPY constructor, I programmed a lot, but never heard about it, thanks a lot again :))) ...
-
operator+, problems...Here's my code:
class CStr { private: char *buffer; public: //Construction CStr(void) { buffer=NULL; } CStr(const char *init) { if (init!=NULL) { buffer = new char[strlen(init)+1]; strcpy(buffer,init); } else buffer=NULL; } //Destruction ~CStr(void) { Empty(); } //Operations void Empty() { delete[] buffer; } //Overloads CStr& operator= (const char* val) { Empty(); if (val!=NULL) { buffer = new char[strlen(val)+1]; strcpy(buffer,val); } else buffer=NULL; return *this; } CStr operator+ (const char* val) { CStr temp; char *pBuf=new char[strlen(val)+strlen(buffer)+1]; strcpy(pBuf,buffer); strcat(pBuf,val); temp.buffer=pBuf; return temp; } CStr& operator= (const CStr val) { if (this == &val) return *this; Empty(); buffer = new char[strlen(val.buffer)+1]; strcpy(this->buffer,val.buffer); return *this; } };
I use this class like this:CStr str("Test"); printf("%s",str+"ing");
But, instead of printing Testing it returns lot's of garbage. I ran the debugger, it shows me that operator+ returns bad object :( What shall I do ??? -
operator+, problems...Well, yes!
-
Initialising a items in a structureYou can use constructor in your structure like this:
struct MyStructure { char blablabla[200]; MyStructure() { strcpy(this->blablabla,"Testing"); } }
-
operator+, problems...Hey, everyone, I have a problem with overloading operator+, here is the code:
CStr operator+ (const char* val) { CStr temp; char *pBuf=new char[strlen(val)+strlen(buffer)+1]; strcpy(pBuf,buffer); strcat(pBuf,val); temp.buffer=pBuf; return temp; }
Here buffer is a member-variable which holds string data. I don't understand why, but this method never returns concatenated strings, it returns some garbage instead. Any ideas ?