为什么已经声明的变量传递给函数后提示未声明?

在做剑指offer的二叉树重构题目时遇到了如下问题:
int searchInt(vector<int> vec, int val)
 {
auto iter = vec.begin();
int index = 0;
for (;*iter != val;++iter)//不用考虑查找失败,因为一定会查找成功
++index;
return index;

}
TreeNode* reConstructBinaryTree(vector<int> pre, vector<int> vin)
{
int n = pre.size();
auto it_pre = pre.begin();
auto it_vin = vin.begin();


if (n>0)
{

TreeNode *t = new TreeNode(*it_pre);
int mid = searchInt(vin, t->val);
//借助vector的范围拷贝
vector<int> LnewPre;//传给左子树的新vector
vector<int> LnewIn;
vector<int> RnewPre;//传给右子树的新vector
vector<int> RnewIn;
LnewPre.assign(it_pre + 1, it_pre + 1 + mid);
LnewIn.assign(it_vin, it_vin + mid);
RnewPre.assign(it_pre + mid + 1, it_pre + n);//终点为it_pre+mid+1+n-mid-1
RnewIn.assign(it_vin + mid + 1, it_vin + n);//终点为it_vin+mid+1+n-mid-1

t->left = reConstructBinaryTree(LnewPre,LnewIn);//注意提给参数是vector
t->right = reConstructBinaryTree(RnewPre,RnewIn);
return t;
}
return nullptr;

}

这里的LnewPre,LnewIn等4个vector都是声明过了的,但是传给递归的reConstructBinaryTree(LnewPre,LnewIn)时提示LnewPre,LnewIn未声明,这是为什么呢?



#C/C++#
全部评论
重新编译以后仍是这样的 ,而且牛客的编译也是报告同样的错误
点赞 回复 分享
发布于 2018-05-14 09:41
如果能运行那就是vs的插件出问题了 重启vs或者右键项目重新扫描
点赞 回复 分享
发布于 2018-05-14 09:37

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务