Segmentation fault: class of string


U

unlexx

Hello. Why? :)
class mA
{
public:
int Id;
int gr_id;
string ppatch;
double p;
mA():ppatch("123"){};//initializing the variables
};
int main()
{
int counter=300;
//...
mA *pma = new mA[counter-1];
while (counter--){
pma[counter].gr_id=100; //ok
pma[counter].ppatch="1"; //fault
// pma[counter].ppatch.assign(str, 0, str.length()); //fault
// std::cout << pma[counter].ppatch.c_str()<< std::endl; //fault ???
}
}
 
Ad

Advertisements

S

SG

int counter=300;
mA *pma = new mA[counter-1];
while (counter--){
pma[counter].gr_id=100; // ok
pma[counter].ppatch="1"; // fault
}

Try
mA *pma = new mA[counter];

or better yet: std::vector<mA>

Cheers!
SG
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top