0

hi

I keep getting the segmentation fault thingie and i think i know the line that is causing the problem, but i dunno how to fix it.

please take a look at the code.

...
class AnotherClass{
    ...
};

...

class AClass{
    private:
        list<AnotherClass> listName;
        list<AnotherClass>::iterator it;
        ...
    public:
        void disp();
};
void AClass::disp(){
    cout<<"show this statement"<<endl;
    cout<<"size of listName = "<<listName.size()<<endl;
    cout<<"XXXXXXXXXXXXXXXXXXX"<<endl;
    ...
}

int main(){
    ...
    AClass inst;
    int retVa1 = pthread_create(&thread1, NULL, func, &inst);
    ...
}

void *func(void *ptr){
    AClass *inst = (AClass *) &ptr;
    ...
    inst -> disp();
    ...
}

The output is

show this statement
Segmentation fault

wat is wrong with my codes? please help...

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Sky Diploma
1

> AClass *inst = (AClass *) &ptr;
Probably the & here.

Votes + Comments
I agree. Without the ampersand it's just the address the pointer is pointing to, not the address of the pointer itself!
0

I am not sure but !!
I think you will first need to convert the return type of the size type to int. try using the following instead.

cout<<"size of listName = "<<(int)listName.size()<<endl;

This happens because list::size returns a size_type variable where as you will need an int i guess.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.