我正在尝试将我的methodDecl节点存储在RecursiveASTVisitor
中的地图中std::map<std::string, ObjCMethodDecl> ObjCMethodsMap;
目前我正在存储它
virtual bool HandleTopLevelDecl (DeclGroupRef DG) {
for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; ++i) {
Decl *D = *i;
if (ObjCMethodDecl *methodDecl = dyn_cast<ObjCMethodDecl>(D)) {
std::string methodName = methodDecl->getNameAsString();
ObjCMethodsMap[methodName] = ObjCMethodDecl(*methodDecl);
}
}
}
当我尝试使用它时,我会这样做
ObjCMethodDecl methodDecl = ObjCMethodsMap["textFieldShouldReturn:"];
Visitor->TraverseDecl(&methodDecl);
这可能更像是一个C ++问题,但是我在将它存储在引用中的方式做错了吗?
以下是我收到的编译错误消息。我不确定它现在说什么,因为它引用的不是我的代码中的内容,并没有告诉我它来自哪一行。这就是为什么我想也许我在C ++中做错了什么
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1645:31: error: no matching constructor for initialization of 'clang::ObjCMethodDecl'
::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1572:18: note: in instantiation of function template specialization 'std::__1::allocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char>, clang::ObjCMethodDecl>, void *> >::construct<clang::ObjCMethodDecl>' requested here
{__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1453:14: note: in instantiation of function template specialization 'std::__1::allocator_traits<std::__1::allocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char>, clang::ObjCMethodDecl>, void *> > >::__construct<clang::ObjCMethodDecl>' requested here
{__construct(__has_construct<allocator_type, pointer, _Args...>(),
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/map:1366:20: note: in instantiation of function template specialization 'std::__1::allocator_traits<std::__1::allocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char>, clang::ObjCMethodDecl>, void *> > >::construct<clang::ObjCMethodDecl>' requested here
__node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/map:1380:29: note: in instantiation of member function 'std::__1::map<std::__1::basic_string<char>, clang::ObjCMethodDecl, std::__1::less<std::__1::basic_string<char> >, std::__1::allocator<std::__1::pair<const std::__1::basic_string<char>, clang::ObjCMethodDecl> > >::__construct_node_with_key' requested here
__node_holder __h = __construct_node_with_key(__k);
^
/Users/jeremy/Desktop/clang-llvm/llvm/tools/clang/tools/extra/myASTChecker/MyASTChecker.cpp:272:55: note: in instantiation of member function 'std::__1::map<std::__1::basic_string<char>, clang::ObjCMethodDecl, std::__1::less<std::__1::basic_string<char> >, std::__1::allocator<std::__1::pair<const std::__1::basic_string<char>, clang::ObjCMethodDecl> > >::operator[]' requested here
ObjCMethodDecl methodDecl = ObjCMethodsMap[selectorName];
^
/Users/jeremy/Desktop/clang-llvm/llvm/tools/clang/include/clang/AST/DeclObjC.h:113:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided
class ObjCMethodDecl : public NamedDecl, public DeclContext {
^
/Users/jeremy/Desktop/clang-llvm/llvm/tools/clang/include/clang/AST/DeclObjC.h:113:7: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 0 were provided
/Users/jeremy/Desktop/clang-llvm/llvm/tools/clang/include/clang/AST/DeclObjC.h:226:3: note: candidate constructor not viable: requires at least 6 arguments, but 0 were provided
ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,