我目前正在停电,而且我是c ++和CORBA的新手。我试图分配一个CORBA :: Char,但我得到一个Compiler-Error“错误:从'CORBA :: Char *'无效转换为'CORBA:Char'。有没有人有想法,我的代码有什么问题以及如何写得对吗?
谢谢! 西蒙
class Medium_impl : virtual public POA_Media::Medium {
public:
CORBA::Char gettype();
void settype(CORBA::Char);
private:
CORBA::Char type;
};
Medium_impl::Medium_impl (char* _oidstr) {
type='V';
}
void Medium_impl::settype(CORBA::Char _type){
type = _type;
}
CORBA::Char Medium_impl::gettype(){
return type;
}
我在测试中得到错误 - Methode aref - > settype(type [i]);
void Mediathek_impl::test (void) {
CORBA::Char type[10][1];
strcpy(type[0],"V");
for(int i = 0; i<=9;i++){
char oidstr[20];
sprintf(oidstr,"medium_%d.acc",count);
PortableServer::ObjectId_var tmpoid=PortableServer::string_to_ObjectId(oidstr);
CORBA::Object_var obj = mypoa->create_reference_with_id (tmpoid,"IDL:Medium:1.0");
::Media::Medium_ptr aref = ::Media::Medium::_narrow (obj);
assert (!CORBA::is_nil (aref));
oid[count] = mypoa->reference_to_id(aref);
//here I get the Compiler-error
aref ->settype(type[i]);
count ++;
}
答案 0 :(得分:1)
type
已声明为:
CORBA::Char type[10][1];
然后,type[i]
为CORBA::Char*
,构建者抱怨不知道如何将其转换为CORBA::Char
。我想你想要:
aref ->settype(type[i][0]);
或
CORBA::Char type[10];
strcpy(type,"V");