Hi,
I am still getting the same output and i donn see the copy constructor being invoked. While browsing through few sites, i think i found the answer to my question
The C++ standard explicitly allows compilers to eliminate temporary objects if the only way of detecting if those temporary objects exist is to track constructor and destructor calls.
A special case of this is the Return Value Optimisation (RVO),...
User Profile
Collapse
-
-
Hi,
Thanks for the reply. Overloading = has solved the problem. But i want to understand why the destructor for temp is not called when i said
String S3 = S2 + S1
instead of
S3 = S2 + S1.
I was under the impression that in the first case the copy constructor is invoked. But it does not seem so.Leave a comment:
-
Hi,
I tried deleting using delete []p. But the the output is still the sameLeave a comment:
-
-
I thought when you say
String S3 = S2 + S1
A copy constructor will be invoked for S3 and a destructor will be invoked for the temp obj in the operator + functionLeave a comment:
-
I understand that. But why is the destructor not being called in the second case?
i mean when i say
String S3 = S1 + S2;Leave a comment:
-
Constructor and desstructor problem
/*Program to do manipulations on a string*/
#include <iostream>
using namespace std;
class String
{
int len;
char *p;
public:
String ()
{
cout << "default constructor " << this << endl;
len = 0;
p = NULL;
}
String...
No activity results to display
Show More
Leave a comment: