ofScopedLock build error, lock unlock works

I have a templated class that uses ofScopedLock, it’s a mutexed list like so:

template <typename T>
class MutexList
{
        list<T> queue;
        ofMutex mutex;
public:
	MutexList(void)
	{
	}

	~MutexList(void)
	{
	}


	int size()
	{
		mutex.lock();
		int queueSize = queue.size();
		mutex.unlock();
		return queueSize;
	}
            //...
}

When I try to implement the size() function with an ofScopedLock VS2012 gives me :

Error 197 error C2248: ‘Poco::ScopedLock::ScopedLock’ : cannot access private member declared in class ‘Poco::ScopedLock’

The same with some other functions. Any idea why?

can you post the code that fails?

Argh, my bad.

This didn’t work:

ofScopedLock(mutex);

This does:

ofScopedLock(this->mutex);

I probably have another mutex with the same name somewhere in a derived class.
Cheers!

yes there’s now std::mutex and since we include the whole std namespace that can be problematic at times we should rename that mutex to mtx or similar.

by the way, i think this:

ofScopedLock(mutex)

won’t work since the scope of an anonimous variable is just the line in which it’s defined so it’ll go away immediately unlocking the mutex after that line. you need to create a variable that lasts until the end of that block:

ofScopedLock lock(mtx)

also this is now present in the stl so it’s better to use that directly:

std::unique_lock lck(mtx)

…Good thing to know about anonimous variables.

Thanks!

Actually there was another reason to get that error, it’s that my class did not define a copy constructor for my class and the compiler wasn’t able to generate one while using std::mutex (or Poco::FastMutex).

I just created an empty copy constructor, I wasn’t able to make it private or declare it as delete.