【问题标题】:invalid conversion from CORBA::Char* to CORBA::Char从 CORBA::Char* 到 CORBA::Char 的无效转换
【发布时间】:2013-11-24 12:02:16
【问题描述】:

我目前停电,我是 C++ 和 CORBA 的新手。我试图分配一个 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;
}

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

【问题讨论】:

  • 当它需要一个字符时,你是一个数组(衰减为一个指针)。
  • 您的代码有什么错误正是错误消息所说的:您正在尝试将 char 指针存储到 char 中。如何解决它取决于您实际想要做什么。你还没有解释你真正想要做什么
  • IDL 到 C++11 语言映射比 IDL 到 C++ 语言映射更容易学习,查看swsupport.remedy.nl 了解更多详细信息以及如何获得 TAOX11 评估许可证

标签: c++ corba


【解决方案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");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    • 2017-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多