Using a class function in int main()

前端 未结 6 953
悲哀的现实
悲哀的现实 2020-12-20 09:49

I am having problems calling my functions from my main program.
These functions HAVE to be in my class.
How do I access them from my int main()?

#inc         


        
6条回答
  •  Happy的楠姐
    2020-12-20 10:21

    Functions inside a class are called methods. You need to instantiate an object of that class to be able to use it's methods:

    myCountingSemaphoreUsingBinarySemaphore obj; // obj is an instance of the class
    
    obj.waitSemaphore(&mutex1);
    
    obj.signalSemaphore(&mutex1);
    

    EDIT:

    By the way, pthread_create and pthread_join take a pthread_t* and not a mutex!

    int pthread_create(pthread_t* thread, 
                       pthread_attr_t* attr, 
                       void* (*start_routine)(void*), 
                       void* arg);
    

提交回复
热议问题