私のコードは
TreeNode *sortedArrayToBST(vector<int> &num) {
function<TreeNode*(int,int)> func=
[&func,&num](int s, int e){
TreeNode* p = NULL;
if(s>e) return NULL; // change to return p would compile
int m = (s+e)/2;
p = new TreeNode(num[m]);
p->left = func(s,m-1);
p->right = func(m+1,e);
return p;
};
return func(0,num.size()-1);
}
Solutions.cpp:957:21: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null]
Solutions.cpp:959:29: error: inconsistent types ‘TreeNode*’ and ‘int’ deduced for lambda return type
Solutions.cpp:959:29: error: invalid conversion from ‘TreeNode*’ to ‘int’ [-fpermissive]
Solutions.cpp:962:12: error: inconsistent types ‘TreeNode*’ and ‘int’ deduced for lambda return type
Solutions.cpp:962:12: error: invalid conversion from ‘TreeNode*’ to ‘int’ [-fpermissive]
TreeNode* 型の NULL を作成してコードを修正しました。私の質問は、NULL ポインターを返すためだけに一時変数を宣言する必要がないように、型で NULL を作成する方法です。NULL(TreeNode); のようなもの。