Click here to Skip to main content
15,890,882 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: C++ - code executed upon definite program termination Pin
Heng Xiangzhong7-Apr-14 16:26
Heng Xiangzhong7-Apr-14 16:26 
SuggestionRe: C++ - code executed upon definite program termination Pin
David Crow7-Apr-14 16:43
David Crow7-Apr-14 16:43 
GeneralRe: C++ - code executed upon definite program termination Pin
Heng Xiangzhong7-Apr-14 19:20
Heng Xiangzhong7-Apr-14 19:20 
GeneralRe: C++ - code executed upon definite program termination Pin
CPallini7-Apr-14 23:43
mveCPallini7-Apr-14 23:43 
GeneralRe: C++ - code executed upon definite program termination Pin
Heng Xiangzhong8-Apr-14 0:27
Heng Xiangzhong8-Apr-14 0:27 
GeneralRe: C++ - code executed upon definite program termination Pin
liquid_8-Apr-14 11:29
liquid_8-Apr-14 11:29 
GeneralRe: C++ - code executed upon definite program termination Pin
Heng Xiangzhong8-Apr-14 15:25
Heng Xiangzhong8-Apr-14 15:25 
QuestionOperator overload question Pin
econy5-Apr-14 13:42
econy5-Apr-14 13:42 
Please read the following code:
C++
class MyString {
	private:
		char *str;
	public :
	MyString():str(NULL){}
	MyString(const char* iStr);
	MyString(const MyString& iMyStr);
	~MyString();
	
	MyString& operator=(const MyString &iMystr);
	
	//friend MyString& operator+(const char* iStr, const MyString& iMyStr);
	friend char* operator+(const char* iStr, const MyString& iMyStr);
};

//Friend + , "xxx" + S
char* operator+(const char* iStr, const MyString& iMyStr)
{
	char * newStr = NULL;
	newStr = new char[strlen(iStr)+strlen(iMyStr.c_str()) + 1];
	strcpy(newStr,iStr);
	strcat(newStr,iMyStr.c_str());

	return newStr; //works well
        //return MyString(newStr); // compile error
}

int main()
{
   MyString S1("fgh");
  MyString S2("abc");
  
  S1 = "cde" + S1;
  return 0;
}

I set break point, and I found if I use commented statements, compiler popups exception.
But I think both commented statements ,and non comment statements
are same.both use constructor to construct a temporary object.

Don't know why it does not work.
AnswerRe: Operator overload question Pin
Richard Andrew x645-Apr-14 15:18
professionalRichard Andrew x645-Apr-14 15:18 
GeneralRe: Operator overload question Pin
econy7-Apr-14 5:49
econy7-Apr-14 5:49 
GeneralRe: Operator overload question Pin
Richard MacCutchan7-Apr-14 6:04
mveRichard MacCutchan7-Apr-14 6:04 
AnswerRe: Operator overload question Pin
CPallini7-Apr-14 2:28
mveCPallini7-Apr-14 2:28 
GeneralRe: Operator overload question Pin
econy7-Apr-14 5:51
econy7-Apr-14 5:51 
GeneralRe: Operator overload question Pin
CPallini7-Apr-14 6:21
mveCPallini7-Apr-14 6:21 
QuestionReference variable assignment and copy constructor call Pin
trinh.nguyen4-Apr-14 19:05
trinh.nguyen4-Apr-14 19:05 
AnswerRe: Reference variable assignment and copy constructor call Pin
Randor 4-Apr-14 21:47
professional Randor 4-Apr-14 21:47 
GeneralRe: Reference variable assignment and copy constructor call Pin
trinh.nguyen4-Apr-14 23:10
trinh.nguyen4-Apr-14 23:10 
GeneralRe: Reference variable assignment and copy constructor call Pin
Randor 4-Apr-14 23:57
professional Randor 4-Apr-14 23:57 
QuestionSoftware USB write blocker for linux Pin
dream qq4-Apr-14 13:32
dream qq4-Apr-14 13:32 
QuestionHow to change tab event of property sheet Pin
kangte22223-Apr-14 15:15
kangte22223-Apr-14 15:15 
QuestionRe: How to change tab event of property sheet Pin
David Crow3-Apr-14 16:43
David Crow3-Apr-14 16:43 
AnswerRe: How to change tab event of property sheet Pin
Malli_S3-Apr-14 23:59
Malli_S3-Apr-14 23:59 
AnswerRe: How to change tab event of property sheet Pin
Randor 4-Apr-14 8:56
professional Randor 4-Apr-14 8:56 
QuestionGetWindowRect(),GetClientRect() question Pin
econy3-Apr-14 8:42
econy3-Apr-14 8:42 
AnswerRe: GetWindowRect(),GetClientRect() question Pin
Randor 3-Apr-14 9:08
professional Randor 3-Apr-14 9:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.