C++ osx授权服务错误
因此,我试图制作一个需要root权限的应用程序,我发现了这个函数,但我不断得到一个错误,“没有匹配的成员函数用于调用‘push_back’”,我尝试将向量更改为string,然后将其转换为char*但后来我得到了分段错误11C++ osx授权服务错误,c++,macos,C++,Macos,因此,我试图制作一个需要root权限的应用程序,我发现了这个函数,但我不断得到一个错误,“没有匹配的成员函数用于调用‘push_back’”,我尝试将向量更改为string,然后将其转换为char*但后来我得到了分段错误11 static bool execute(常量字符串和程序、常量向量和参数){ 授权参考; if(AuthorizationCreate(NULL,kAuthorizationEmptyEnvironment,kAuthorizationFlagDefaults,&ref)!
static bool execute(常量字符串和程序、常量向量和参数){
授权参考;
if(AuthorizationCreate(NULL,kAuthorizationEmptyEnvironment,kAuthorizationFlagDefaults,&ref)!=errAuthorizationSuccess){
返回false;
}
授权项目={
kAuthorizationRightExecute,0,0,0
};
授权权限={1,&item};
const AuthorizationFlags flags=kauthorizationflagsdefaults
|kAuthorizationFlagInteractionAllowed
|KauthorizationFlag预授权
|Kauthorization鞭毛延伸灯;
if(授权版权(参考和权利、KAAuthorizationEmptyEnvironment、flags,0)!=errAuthorizationSuccess){
授权自由(参考,授权权);
返回false;
}
向量args;
for(vector::const_iterator it=arguments.begin();it!=arguments.end();++it){
args.push_back(it->c_str());//此处错误,“没有匹配的成员函数用于调用“push_back”
}
参数推回(0);
OSStatus status=AuthorizationExecuteWithPrivileges(ref,program.c_str(),kAuthorizationFlagDefaults,&args[0],0);
授权自由(参考,授权权);
返回状态==errAuthorizationSuccess;
}
尝试将向量args更改为向量args
。函数c_str()
返回一个const char*
@AndrewB。这不适用于AuthorizationExecuteWithPrivileges接受字符*而不是常量字符*,无论如何,谢谢。如果有什么可以解决错误的话,请尝试const\u cast(it->c\u str())
。您可能已经知道这一点很久了。@AndrewB。行了,干杯