Access to the C structure as a C ++ class

Is there a workaround for this error in gcc ?

In particular, I think I'm in an error compiling the shell for pthread_mutex_t. The title is as follows:

class DerivedClass: public pthread_mutex_t{
  public:
     DerivedClass() {}
     ~DerivedClass(){}
     DerivedClass someFunction(){}
};

The code refers to a legacy system and is used to compile on GCC 3.2.x, but will not apply to GCC 4.1.2.

... In theory, I think I could recompile everything on the GCC reverse version or reorganize the link sources so as not to use the shell, but I want to see if there is an easier way in the first place.

Many thanks.

+3
source share
1 answer

Fixed bug in GCC 4.6.0, but if you need it now, use composition instead:

class DerivedClass {
  public:
    pthread_mutex_t mutex;
// ...
}

, pthread_mutex_t *, , ; DerivedClass * pthread_mutex_t * . operator pthread_mutex_t *().

+5

Source: https://habr.com/ru/post/1791689/


All Articles