Here is the example of the "scoped lock" idiom with common mistake: no local variable is created, so lock is not in effect. This code compiles flawlessly both with VC++ 2010 and Comeau C++ online:

```
class Mutex
{
public:
    void lock() {}
};

class ScopedLock
{
public:
    ScopedLock() : m_pm(0) {}
    ScopedLock(Mutex& m) : m_pm(&m) { m_pm->lock(); }

private:
    Mutex* m_pm;

private:
    ScopedLock& operator =(const ScopedLock&);
    ScopedLock(const ScopedLock&);
};

class X
{
public:
    void foo() const
    {
        ScopedLock(m_mutex);
    }

private:
    Mutex m_mutex;
};

int main()
{
    X x1;
    x1.foo();
}

```

If default constructor for ScopedLock is commented out, then both compilers give an error:

> 
> error C2512: 'ScopedLock' : no appropriate default constructor available
> 
> 
> 

(When `ScopedLock` used correctly, i.e. local variable is created: `ScopedLock guard(m_mutex);`, then compilation fails as expected. Declaring `m_mutex` as mutable fixes the problem.)

I have two questions:

1. Why `X::foo` compiles? It seems that compiler was able to cast `const Mutex&` to `Mutex&` somehow.
2. What role plays `ScopedLock` default constructor, so the compilation succeeds?

Thanks.

**Update:** I found the answer. It appears that `ScopedLock(m_mutex);` statement creates a local variable `m_mutex` of type `ScopedLock`. Not a temporary. That's why `ScopedLock::ScopedLock` default constructor is required.