constructors.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Includes
00010 *****************************************************************************/
00011 
00012 #include <iostream>
00013 
00018 /*****************************************************************************
00019 ** Classes
00020 *****************************************************************************/
00021 
00022 class A {
00023     public:
00024         A(int i) : var(i) { std::cout << "Constructor" << std::endl; }
00025         A(const A& a) { std::cout << "Copy constructor" << std::endl; }
00026         ~A() { std::cout << "Destructor" << std::endl; }
00027         void f() {};
00028     private:
00029         int var;
00030 };
00031 
00032 /*****************************************************************************
00033 ** Functions
00034 *****************************************************************************/
00035 
00036 A f() {
00037     return A(3);
00038 }
00039 
00040 A g() {
00041     A a(4);
00042     return a;
00043 }
00044 
00045 /*****************************************************************************
00046 ** Main
00047 *****************************************************************************/
00048 
00049 int main() {
00050 
00051     std::cout << std::endl;
00052     std::cout << "***********************************************************" << std::endl;
00053     std::cout << "            Normal Constructor : A a(3)" << std::endl;
00054     std::cout << "***********************************************************" << std::endl;
00055     std::cout << std::endl;
00056 
00057     A a1(3); a1.f();
00058 
00059     std::cout << std::endl;
00060     std::cout << "***********************************************************" << std::endl;
00061     std::cout << "             Copy Constructor : A a2(a)" << std::endl;
00062     std::cout << "***********************************************************" << std::endl;
00063     std::cout << std::endl;
00064 
00065     A a2(a1); a2.f();
00066 
00067     std::cout << std::endl;
00068     std::cout << "***********************************************************" << std::endl;
00069     std::cout << "       Constructor Assignment w/ Function : A a3 = f();" << std::endl;
00070     std::cout << "***********************************************************" << std::endl;
00071     std::cout << std::endl;
00072 
00073     A a3 = f(); a3.f();
00074 
00075     std::cout << std::endl;
00076     std::cout << "***********************************************************" << std::endl;
00077     std::cout << " Constructor Assignment w/ Non Temp Function : A a4 = g();" << std::endl;
00078     std::cout << "***********************************************************" << std::endl;
00079     std::cout << std::endl;
00080 
00081     A a4 = g(); a4.f();
00082 
00083     std::cout << std::endl;
00084     std::cout << "***********************************************************" << std::endl;
00085     std::cout << "                  Program Finished" << std::endl;
00086     std::cout << "***********************************************************" << std::endl;
00087     std::cout << std::endl;
00088 
00089 
00090     return 0;
00091 }


ecl_utilities
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:39