#include <iostream>
using namespace std;
template <typename T> class tt
{
    public :
    int data;
    tt()
    {
        std::cout << std::endl << "   CONSTRUCTOR" << std::endl;
    }
    tt(const tt & that)
    {
        std::cout << std::endl << "    COPY CONSTRUCTOR" << std::endl;
    }
};
tt<int> test(void)
{
    std::cout << std::endl << "      INSIDE " << std::endl; tt<int> a; a.data =10 ;return a;
}
int main() {
    // your code goes her
    //tt<int> b;
    tt<int> a =test();
    cout<<a.data; //so that return value optimisation doesn't take place
    return 0;
}
Why is the copy constructor not getting called in this case?
It gets called in the following case though
tt<int> b;
tt<int> a =b;
code link : http://ideone.com/e9lq3C
edit : This is not duplicate of What are copy elision and return value optimization?, because returned value is being referenced inside code.
 
     
     
    