Class as a return type : Basics « Function « C++

Class as a return type

Class as a return type
#include <iostream>
using namespace std;

class myclass {
  myclass(const myclass &o);
  myclass f();

  cout << "Constructing normally\n";

myclass::myclass(const myclass &o)
  cout << "Constructing copy\n";

myclass myclass::f()
  myclass temp;

  return temp;

int main()
  myclass obj;

  obj = obj.f();

  return 0;


Related examples in the same category

1.Another example of a conversion functionAnother example of a conversion function
2.Computes the factorial of an integer iteratively: a loop, and recursively
3.A C++ program with several functionsA C++ program with several functions
4.Throwing an exception from a functionThrowing an exception from a function