segnementation fault

Hello im getting a segnementation fault and i dont know how to fix it ,i think it happens when i use new and i try to create a pointer to a class that i use in my project .Here is the code:

artifacts *artptr[10];
cout<<"just created a table of artifacts pointers"<<endl;
//paintings paint;
//artptr=new artifacts *[10];
for (int i=0;i<10;i++){
int length1;
length1=rand()%10+1;
int width1;
width1=rand()%10+1;


int volume1;
volume1=rand()%50+1;

cout<<"meta thn tyxaia arxikopoihsh timvn"<<endl;


if (rand()%2){
cout<<"creating a pointer to painting"<<endl;
//paintings *paint;
//artptr.push_back (new paintings(length,width,techValue));
artptr[i]=new paintings(length1,width1,techValue);


}
else{
cout<<"creating a pointer to sculpures"<<endl;

//artptr.push_back (new sculptures(volume,matValue));
artptr[i]=new sculptures(volume1,matValue);

}

}


where sculptures and paintings are derived classes of artifacts
Last edited on
Hello mariolostre,

Welcome to the forum.

This is only part of your code. It is hard to tell what is happening without the rest of the code and the actual error messages the you received.

Not knowing where this bit of code is meant to be makes it difficult to compile and test.

Andy
you were better off doing the vectors than pointers, I would go back to that. Odds are you had a pointer blowout on artptr.
i have tried with vectors but it doest work,do you think it can be caused by the constructor of the inherrited class paintings or sculptures??
No idea why it didn't work. Try it again with vectors, clean it up, and if it does not work post the new code and we will look into it.

if it fails on something like

vector <myclass> v(10); //fail?
its probably a ctor issue, yes.

Topic archived. No new replies allowed.