2013-11-24 35 views
2

我目前有一箇中斷,我是新的c + +和CORBA。我想分配一個CORBA :: Char,但是我得到一個編譯器錯誤「錯誤:從'CORBA :: Char *'無效轉換爲'CORBA:Char'。有沒有人有一個想法,我的代碼有什麼問題,以及如何寫糾正從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(類型[1]);?!

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

你是一個數組(衰減到指針)時,它需要一個字符。 – chris

+1

你的代碼的錯誤*正是錯誤消息所說的:你試圖將一個char指針存儲到char中。如何解決這個問題取決於你真正想做什麼。你還沒有解釋你實際想要做什麼*做* – jalf

+0

IDL到C++ 11語言映射比IDL到C++語言映射更容易學習,請查閱http://swsupport.remedy.nl瞭解更多信息詳情以及如何獲得TAOX11的評估許可 –

回答

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"); 
相關問題