I need to make the size of the array defined inside the class as situation dependent value. To clarify the point , the following code having fixed array size shows no error
class CMinimalServer : public GBDataAccess
{
public:
DWORD IdG[30];
VARIANT Value[30];
WORD Quality[30];
FILETIME Timestamp[30], ft;
HRESULT Error[30];
But I need to make the size of the array which is '30' in the above case as an dependable value. By this I mean to say that suppose in other part of the code, I have
if (a==b)
Number = 10;
else
Number = 30;
The size of the array should be 10 and 30 accordingly.
But the following code shows an error
class CMinimalServer : public GBDataAccess
{
public:
DWORD IdG[Number ];
VARIANT Value[Number ];
WORD Quality[Number ];
FILETIME Timestamp[Number ], ft;
HRESULT Error[Number ];
I tried
#define Number 16
at the top and the above code showed no error but the problem is i cannot the modify the variable in other part of the code
//// Some issue in the solution
I have modified the code as per the suggestion: I have to make functions inside the class (createTag) .
// Class definition
class CMinimalServer : public GBDataAccess
{
public:
struct Entry
{
DWORD IdG;
VARIANT Value;
WORD Quality;
FILETIME Timestamp;
HRESULT Error;
};
private:
FILETIME ft;
void createTag()
{
DWORD ids[NumberOfPoints],i;
VARIANT val;
val.vt = VT_BOOL;
unsigned c=0;
for (i = 0; i<NumberOfPoints; i++)
{
wchar_t opcid[NumberOfPoints];
wsprintfW(opcid, L"Item%02i", i+1);
val.boolVal = VARIANT_FALSE;
srv.GBCreateItem(&ids[i], i, opcid, OPC_READABLE|OPC_WRITEABLE, 0, &val);
Entry.IdG[c] = ids[i];
Value[c].vt= VT_BOOL;
c++;
}
.....
}
//Main function
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
CMinimalServer() = default;
CMinimalServer(int number) : tab_(number){};
std::vector<Entry> tab_ = std::vector<Entry>(30);
}
The issues are:
- How to define idG vector array inside the CreateTag function.
Entry.idG[c] is showing error.
- The 'NumberOfPoints' in the loop of createTag function is also equal to 30. how to assign this value in the main function.
- How to make another vector array ids . can i defined it in the same struct entry and call it in createTag.
std::vector?