我目前有一个停电,我是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;
}

我在test-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 ++;
}

最佳答案

type已声明为:

CORBA::Char type[10][1];

然后,type[i]CORBA::Char*,并且构建器抱怨不知道如何将其转换为CORBA::Char。我认为您想要:
aref ->settype(type[i][0]);

要么
CORBA::Char type[10];

strcpy(type,"V");

关于c++ - 从CORBA::Char *到CORBA::Char的无效转换,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20174220/

10-11 01:12