This would be a bit easier to follow and more useful if you choose to create a regular instance of the struct.
Code:
typedef struct tagASTRUCT
{
int m_data;
void Create(int data)
{
m_data = data;
}
} ASTRUCT;
ASTRUCT *object;
>object = new tagASTRUCT[10];
In an array you determine the element and access the item with the dot operator. You can use the -> operator, but only on the first element.
Code:
#include <iostream>
typedef struct tagASTRUCT
{
int m_data;
void Create(int data)
{
m_data = data;
}
} ASTRUCT;
ASTRUCT *object;
int main ( void )
{
object = new tagASTRUCT[2];
object->Create(10);
object[1].Create(20);
std::cout<< object->m_data <<"\n";
std::cout<< object[1].m_data <<"\n";
return 0;
}
Try changing those access methods around and see what errors you get.
>give me a sample how to specify the size and at the same time use it on runtime?
Use a variable.
Code:
cout<<"Enter the number of records: ";
cin>>size;
object = new tagASTRUCT[size];
-Prelude