0

I'm perplexed...

I have a piece of code thus;

 class logger
{
public:

  std::mutex mut;
  unique_lock< std::mutex> lk(mut);

  // ... snip ... 
}

The line "unique_lock < std::mutex > lk (mut) " fails compilation with this error;

**g++ -pthread --std=c++11 main.cxx main.cxx:42:31: error: mut is not a type

unique_lock< std::mutex> lk(mut);**

However if I change it to... (note the brace initializer is the only difference)

unique_lock< std::mutex> lk(mut);

It compiles just fine.

I have other code that initialises using the non brace initializer that works/compiles fine. Why on earth is this the case, maybe I'm tired :)

Cheers

G

user3613174
  • 669
  • 1
  • 7
  • 13

1 Answers1

0

Bah.... I was tired. I'm using C++11 in class initialization... only works with the braces. Time to go home...

.. a few months later... notice the curly braces...

class logger {

public:

std::mutex mut; unique_lock< std::mutex> lk{mut};

}

user3613174
  • 669
  • 1
  • 7
  • 13