Can a wxSemaphore be created as a public member of a class? Topic is solved

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
softport
Experienced Solver
Experienced Solver
Posts: 61
Joined: Sat Jan 28, 2012 3:55 pm
Location: Houston TX
Contact:

Can a wxSemaphore be created as a public member of a class?

Post by softport »

Hello, I am getting a compiler error when I try to add a semaphore as a public member of a class.
Is this not allowed? I included the header <wx/thread.h>.

I also tried making it private, but that gives the same compiler errors.

Thanks!

Code: Select all

    public:
        ClassReport_IN();
        virtual ~ClassReport_IN();
        
        void init();
        
        // Semaphores
        //=========================
        wxSemaphore semaphore_ucBuffer(1, 1);  // Line 105
40 C:\Program Files\Dev-Cpp\...ClassReport_IN.h:105 expected identifier before numeric constant
40 C:\Program Files\Dev-Cpp\...ClassReport_IN.h:105 expected ',' or '...' before numeric constant
Windows XP, wxDev-C++ 7.4.2.259, wxWidgets 2.8.12, MingW
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Can a wxSemaphore be created as a public member of a cla

Post by doublemax »

This has nothing to do with wxSemaphore, it's a general matter of C++ syntax. You can't initialize a member variable that way.

In the header file:

Code: Select all

wxSemaphore semaphore_ucBuffer;  // Line 105
Then, when you define the constructor, you can pass the parameters:

Code: Select all

ClassReport_IN::ClassReport_IN()
               :semaphore_ucBuffer(1, 1)
{
Use the source, Luke!
softport
Experienced Solver
Experienced Solver
Posts: 61
Joined: Sat Jan 28, 2012 3:55 pm
Location: Houston TX
Contact:

Re: Can a wxSemaphore be created as a public member of a cla

Post by softport »

Thanks doublemax, hadn't realized I was running before learning to walk. Have some reading to do.
Thanks for the lesson!
Windows XP, wxDev-C++ 7.4.2.259, wxWidgets 2.8.12, MingW
Post Reply