I want a compiler (online/ offline) which will not do any copy elison. I want to see the actual output which we've learnt in theory of "constructor and destructors of c++".
Which constructor will be called for the statement "Student s3=func(s1, s4)". None of my copy constructor, parameterized constructor and overloaded assignment operator is called for this statement. Then, how is this object constructing?
I have tested using this compiler too: https://rextester.com/l/cpp_online_compiler_visual
#include<cstring>
#include<iostream>
using namespace std;
class Student
{
char* name;
int id;
public:
Student(char* n, int i)
{
name= new char[strlen(n)+1];
strcpy(name, n);
id=i;
cout<<"Constructor "<<name<<endl;
}
Student(const Student& s)
{
name= new char[strlen(s.name)+1];
strcpy(name, s.name);
id=s.id;
cout<<"Copy constructor "<<name<<endl;
}
void operator = (const Student &s )
{
name= new char[strlen(s.name)+1];
strcpy(name, s.name);
id=s.id;
cout<<"Assignment Operator "<<name<<endl;
}
~Student()
{
cout<<"Destructing "<<name<<endl;
delete[] name;
}
};
Student func(Student s, Student t)
{
return s;
}
int main()
{
Student s1("abcd", 16);
Student s4("wxyz", 17);
Student s3=func(s1, s4);
}