I have function I wrote in some class. I don't understand why when I create object named: Square square; a d'tor of Square is being called when exiting the function. While when I create the object as: Square* square = new Square(); no d'tor is being called.
There is no inheritance at all on the classes.
Here an example for the function in a two versions:
//=======Enter to d'tor in the end of the function to ~Square==========
void DrawShapesApp::addSquare()
{
int row, col;
int edge;
char ch;
Square square;
getSquareInfo(row, col, edge, ch);
square.setAll(row, col, edge, ch);
m_squares.push_back(&square);
}
//=======Doesn't enter to d'tor in the end of the function==========
void DrawShapesApp::addSquare()
{
int row, col;
int edge;
char ch;
Square* square = new Square();
getSquareInfo(row, col, edge, ch);
(*square).setAll(row, col, edge, ch);
m_squares.push_back(&square);
}