Assume that there is a user defined class Student
. Consider the following two functions:
Student someFunc1() {
return *(new Student("John",25));
}
Student& someFunc2() {
return *(new Student("John",25));
}
Without going into the details as to why they have been implemented the way they have been, are they both correct? Somebody told me that there would be a memory leak but how come?