which is of non-class type 报错
c++编译代码遇到which is of non-class type
粗心导致的一个问题,看了很久,记录一下
代码展示
CmdType* Context::getCmdType(const string& req)
{
vector<CmdType* >::iterator iter = _vecCmd.begin();
while((iter != _vecCmd.end()) && (iter->isSupportCmd(req)))
{
iter++;
return *iter;
}
return NULL;
}
In member function 'CmdType* Context::getCmdType(const std::string&)
request for member 'isSupportCmd' in '* iter.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = CmdType**, _Container = std::vector<CmdType*, std::allocator<CmdType*> >]()', **which is of non-class type** 'CmdType*'
分析
查看报错发现粗心导致类型错误, isSupportCmd的调用需要CmdType*,仔细查看代码发现iter->isSupportCmd(req) iter是cmdType**类型,*iter才是
修改
iter->isSupportCmd(req) 修改(*iter)->isSupportCmd(req) 问题解决