I have a class definition of the form
class X { public: //class functions private: A_type *A; //other class variables }; and struct A_type is defined as
struct A_type { string s1,s2,s3; }; Inside the constructor, I allocate appropriate memory for A and try A[0].s1="somestring"; It shows segmentation fault. Is this kind of declaration invalid, or am I missing something
Edit: New code from OP moved from a comment [neilb]
#include <stdio.h> #include <math.h> #include <string> #include <iostream> using namespace std; struct HMMStruct { string a; }; HMMStruct *HMMs; int main() { HMMs=(HMMStruct*)malloc(sizeof(HMMStruct)*2); HMMs[0].a="sdfasasdsdfg"; cout << HMMs[0].a << endl; }