Several things needed to be changed. First, the lambda declaration is strange. Lambdas give their return value at the end (I think it is allowed though, but in my opinion might be read as trying to assign a lambda to a bool variable.
Second, I was unable to do the same with auto or similar keywords capturing the actual type of the lambda as this would imply static constexpr quite far from what you have.
Therefore, I explicitly gave a good type to the lambda (note that types of lambdas are always strange, so it is in many situations better to assign a lambda to a std::function<> if you want readable error messages and it is almost never a problem. If you don't know the signature, you will most likely have to template it. But then, the class with the lambda will be templated, too and there is no problem.
Finally, the initialization of the queue with the element was ill-formed, because it might be difficult to construct all the objects in the right order. Therefore, the initialization has been moved to the constructor of A.
Here is my correction:
#include<queue>
#include<list>
#include<vector>
#include<functional>
using namespace std;
struct B{
std::list<int> list;
};
class A{
function<bool(const B&, const B&)> compare = [](const B& lhs, const B& rhs) ->bool{
return lhs.list.size() >= rhs.list.size();
};
std::priority_queue<B, vector<B>, decltype(compare)> pq;
A():pq(compare){}
};
int main()
{
}
Finally, note that I don't like the member of B to be named list, as list is also the type.