Is it possible to code this way:while(lambda){}

Viewed 1798

The code below was compiled without error:

std::string lastName, chldName;
while([&]()
{
      return true;
})
{
  //codes...
}   

But when I tried this way:

std::string lastName, chldName;
while([&]()
{
      std::cin >>lastName;
      return true;
})
{
  //codes...
}   

The compiler complained that :

error: could not convert 'main()::{(* & lastName)}' from 'main()::' to 'bool'

How to understand this error?Is it possible to use lambda this way?

3 Answers
Related