Click to See Complete Forum and Search --> : Simple and sweet query regarding a C++ class


amolpatil54321
November 20th, 2003, 05:26 AM
I want to adda constructor in this class which can be dynamically initialized.
e.g. CdbParameters(2,12,4,6); CdbParameters(12,4,26,3) etc....
Please le t me know how can I use pointer or any other way to achieve it?
Also suggest improved way to wrie this class?


class CdbParameters
{
public:
// Data Elements
TCHAR m_param1[41];
TCHAR m_param2[33];
TCHAR m_param3[15];
TCHAR m_param4[32];
//parameter variable
TCHAR m_inParam[300];
CdbParameters()
{

memset(m_param1 , '*', 41 );
memset(m_param2 , '*', 33 );
memset(m_param3 , '*', 15 );
memset(m_param4 , '*', 32 );
}


bool checkValuesExists(int j);
bool isRecordExistInDb();

//Parameter Accessor
BEGIN_PARAM_MAP(CdbParameters)
SET_PARAM_TYPE(DBPARAMIO_INPUT)
COLUMN_ENTRY(1, m_inParam)
END_PARAM_MAP()


//Output Accessor
BEGIN_COLUMN_MAP(CdbParameters)
COLUMN_ENTRY(1,m_param1 )
COLUMN_ENTRY(2,m_param2 )
COLUMN_ENTRY(3,m_param3 )
COLUMN_ENTRY(4,m_param4 )
END_COLUMN_MAP()
};

CornedBee
November 20th, 2003, 05:44 AM
Wrong forum

Soni_Sharad
November 20th, 2003, 06:04 AM
Hi.

What do u mean by a dynamic intialization of a constructor?

amolpatil54321
November 20th, 2003, 07:16 AM
Dyanamic constructor means I want to allocate memory dynamically...If u see now the fields memory is fix .eg.
TCHAR m_param1[41];
Please solve it

Soni_Sharad
November 20th, 2003, 07:28 AM
Hi,

1. Use a parameterised constructor with all the TACHARs as parameters.

2. Declare all these variables as pointers.
3. In the constructor, call new to intialize these variables.


e.g.

class MyClass
{
MyClass(TCHAR a1,TCHAR b1,.......)
{
aa = new TCHAR[_tcslen(a1)];
_tcscpy(aa,a);

bb = new TCHAR[_tcslen(b1)];
_tcscpy(bb,b);
.........
.........
.........
}

private:
TCHAR *aa;
TCHAR *bb;
}


Hope this helps.