M
manitu
Hello all,
I am writing a kind of encapsulation of SQL statements in C++ as a
class. I am encountering problems that the destructor of my class
never gets called.
The class should be used as a kind of hierarchical representation of
the different SQL operations such as AND, OR and possible values.
I will post some abbreviated / shortened / simplified (partiyll
pseude) code here.
#include <stdio.h>
#include <stdlib.h>
class SQL
{
public:
SQL(int someOperator); // lets say 0=AND, 1=OR
SQL(char * someString); // lets say we only now AND, OR and
strings
~SQL();
SQL & operator & (SQL & param);
// public for testing purposes
int type; // lets say 0=Operator, 1=String
int value_operator;
char * value_string;
};
SQL::~SQL()
{
printf("I am the destructor\n");
};
SQL::SQL(int someOperator)
{
printf("I am the constructor for operators, my type is %i\n",
someOperator);
type = 0;
value_operator = someOperator;
};
SQL::SQL(char * someString)
{
printf("I am the constructor for string values, my value is
\"%s\"\n", someString);
type = 1;
value_string = someString;
};
SQL & SQL:perator & (SQL & param)
{
return * new SQL( 1 );
};
void showType( SQL & sql )
{
printf("TYPE: %i\n", sql.type);
};
int main()
{
SQL test1("Test 1");
showType( test1 );
return 0;
};
=============> outputs
I am the constructor for string values, my value is "Test 1"
TYPE: 1
I am the destructor
int main()
{
showType( * new SQL("Test 2") & * new SQL("Test 3") );
return 0;
};
=============> outputs
I am the constructor for string values, my value is "Test 3"
I am the constructor for string values, my value is "Test 2"
I am the constructor for operators, my type is 1
TYPE: 0
I cannot explain why there are constructor calls for the three
instances of SQL, but no destructor calls.
Any help would be appreciated.
Thanks
Manuel
I am writing a kind of encapsulation of SQL statements in C++ as a
class. I am encountering problems that the destructor of my class
never gets called.
The class should be used as a kind of hierarchical representation of
the different SQL operations such as AND, OR and possible values.
I will post some abbreviated / shortened / simplified (partiyll
pseude) code here.
#include <stdio.h>
#include <stdlib.h>
class SQL
{
public:
SQL(int someOperator); // lets say 0=AND, 1=OR
SQL(char * someString); // lets say we only now AND, OR and
strings
~SQL();
SQL & operator & (SQL & param);
// public for testing purposes
int type; // lets say 0=Operator, 1=String
int value_operator;
char * value_string;
};
SQL::~SQL()
{
printf("I am the destructor\n");
};
SQL::SQL(int someOperator)
{
printf("I am the constructor for operators, my type is %i\n",
someOperator);
type = 0;
value_operator = someOperator;
};
SQL::SQL(char * someString)
{
printf("I am the constructor for string values, my value is
\"%s\"\n", someString);
type = 1;
value_string = someString;
};
SQL & SQL:perator & (SQL & param)
{
return * new SQL( 1 );
};
void showType( SQL & sql )
{
printf("TYPE: %i\n", sql.type);
};
int main()
{
SQL test1("Test 1");
showType( test1 );
return 0;
};
=============> outputs
I am the constructor for string values, my value is "Test 1"
TYPE: 1
I am the destructor
int main()
{
showType( * new SQL("Test 2") & * new SQL("Test 3") );
return 0;
};
=============> outputs
I am the constructor for string values, my value is "Test 3"
I am the constructor for string values, my value is "Test 2"
I am the constructor for operators, my type is 1
TYPE: 0
I cannot explain why there are constructor calls for the three
instances of SQL, but no destructor calls.
Any help would be appreciated.
Thanks
Manuel