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...

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

commented: I agree. Without the ampersand it's just the address the pointer is pointing to, not the address of the pointer itself! +3

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.