Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 消除C和C+中类似函数之间的重复+;,在EmPy模板中_C++_C_Templates_Duplicates_Empy - Fatal编程技术网

C++ 消除C和C+中类似函数之间的重复+;,在EmPy模板中

C++ 消除C和C+中类似函数之间的重复+;,在EmPy模板中,c++,c,templates,duplicates,empy,C++,C,Templates,Duplicates,Empy,那些东西是 C++ const char * publish__@(spec.base_type.type)(void * untyped_data_writer, const void * untyped_message) { DataWriter * topic_writer = static_cast<DataWriter *>(untyped_data_writer); const __ros_msg_type & ros_message

那些东西是

C++

  const char *
  publish__@(spec.base_type.type)(void * untyped_data_writer, const void * untyped_message)
  {
    DataWriter * topic_writer = static_cast<DataWriter *>(untyped_data_writer);
    const __ros_msg_type & ros_message = *(const __ros_msg_type *)untyped_message;
    __dds_msg_type dds_message;
    conversion_cpp(ros_message, dds_message);

    @(__dds_msg_type_prefix)DataWriter * data_writer =
      @(__dds_msg_type_prefix)DataWriter::_narrow(topic_writer);
    DDS::ReturnCode_t status = data_writer->write(dds_message, DDS::HANDLE_NIL);

    // some common switch statements in C and C++

    }
  }
常量字符*
发布(spec.base\u type.type)(无效*未类型化的数据写入程序,常量无效*未类型化的消息)
{
DataWriter*topic_writer=static_cast(非类型化的数据_writer);
常量ros msg类型和ros消息=*(常量ros msg类型*)非类型消息;
__dds\u消息类型dds\u消息;
转换cpp(ros消息、dds消息);
@(uuu dds_msg_type_前缀)数据写入器*数据写入器=
@(dds msg类型前缀)数据编写器::(主题编写器);
DDS::ReturnCode\u t status=数据写入器->写入(DDS\u消息,DDS::HANDLE\u NIL);
C/C++中常用的开关语句
}
}
C

静态常量字符*
发布(无效*数据写入器、常量无效*酷消息)
{
如果(!data_writer){return“data writer handle为null”;}
如果(!cool_message){return“ros消息句柄为空”;}
DDS::DataWriter*主题编写器=静态转换(数据编写器);
__dds\u消息类型dds\u消息;
const char*err_msg=conversion_c(冷消息和dds消息);
如果(err_msg!=0){返回err_msg;}
@(uuu dds_msg_type_前缀)数据写入器*数据写入器=
@(dds msg类型前缀)数据编写器::(主题编写器);
DDS::ReturnCode\u t status=数据写入器->写入(DDS\u消息,DDS::HANDLE\u NIL);
@[用于规范字段中的字段]@
@[如果field.type.type=='string']@
@[如果field.type.is_数组]@
{
@[如果字段.类型.数组大小]@
size\u t size=@(field.type.array\u size);
@[其他]@
size_t size=dds_message@(field.name)uu.length();
@[如有需要,请结束]@
对于(DDS::ULong i=0;i
这个问题有点特定于我试图参与的一个开源项目,所以我将指出我猜的确切函数。 这是原件 这就是

我需要使用函数指针吗?
另一件事情是C包依赖C++包。

(也许这不是一个好问题,但我是个模糊的问题,但我不知道该怎么做,因为我是这个代码库的新手)< /P>请在这里发布简化的相关代码。“C”函数看起来像是用C++编写的,而“C++”函数写在C(<代码> Value*/COD>参数,YUK)中。你的意思是第一个被声明为

extern“C”
还是类似的?我没有深入了解模板元字符,但根本不清楚为什么需要两个不同的函数。也许你可以澄清区别是什么。这些可能与函数指针有什么关系?是的,它是extern C,请看文章中C方法的链接,或者我可以向您指出它的用途有点牵连。它基本上生成DDS的消息文件,可以与C或C++客户端库一起使用。伙计,我应该问问维修人员,我现在有点困惑。也许是overengineering@madratman:如果定义了(u cplusplus)/extern“C”,那么就没有太多的要点了{<代码> >代码之前使用<代码> STATICORCAST 。除非使用C++编译器,否则它不会编译,所以 IFDEF是多余的。除非有一些东西不能立即看到。我仍然认为使用<代码> Value*/Cord> C++函数的参数是YUK。(它也是YC,但有时是必要的)。但是,我想他们有他们的理由。“ExcN”c使C++中的函数名具有“C’链接(编译器不修改名称)),这样客户端C代码可以使用包含“函数”声明的“C”兼容的头文件链接到(即使用)函数。(由C++编译器编译),客户端的C链接器将链接到使用“C”的名字。“请在这里发布简化的相关代码。”C”函数看起来像是用C++编写的,而“C++”函数则写在C(<代码> Value*/COD>参数,YUK)中。.你的意思是第一个被声明为
extern“C”
或类似的?我没有深入了解模板元字符,但根本不清楚为什么需要两个不同的函数。也许你可以澄清一下区别是什么。这可能与函数指针有什么关系?是的,它是外部C,请查看帖子中C方法的链接,或者其目的有点牵连我可以指给你。它基本上是为DDS生成消息文件,用C或C++客户端库。我应该问维护者,我现在稍微有点困惑。也许,它是overengineering@madratman:如果定义了(u cplusplus)/extern“C”,那么就没有太多的要点了{<代码> >代码之前使用<代码> STATICORCAST 。除非使用C++编译器,否则它不会编译,所以 IFDEF是多余的。除非有一些东西不能立即看到。我仍然认为使用<代码> Value*/Cord> C++函数的参数是YUK。(它也是YC,但有时是必要的)。但是,我想他们有他们的理由。“ExcN”c使C++中的函数名具有“C’链接(编译器不修改名称)),这样客户端C代码可以使用包含“函数”声明的“C”兼容的头文件链接到(即使用)函数。(这是由C++编译器编译的),客户端的C链接器将链接到使用“C”名称。
static const char *
publish(void * data_writer, const void * cool_message)
{
  if (!data_writer) {return "data writer handle is null";}
  if (!cool_message) {return "ros message handle is null";}

  DDS::DataWriter * topic_writer = static_cast<DDS::DataWriter *>(data_writer);
  __dds_msg_type dds_message;
  const char * err_msg = conversion_c(cool_message, &dds_message);
  if (err_msg != 0) {return err_msg;}

  @(__dds_msg_type_prefix)DataWriter * data_writer =
    @(__dds_msg_type_prefix)DataWriter::_narrow(topic_writer);
  DDS::ReturnCode_t status = data_writer->write(dds_message, DDS::HANDLE_NIL);
@[for field in spec.fields]@
@[if field.type.type == 'string']@
@[if field.type.is_array]@
  {
@[if field.type.array_size]@
    size_t size = @(field.type.array_size);
@[else]@
    size_t size = dds_message.@(field.name)_.length();
@[end if]@
    for (DDS::ULong i = 0; i < size; ++i) {
      // This causes the DDS::String_mgr to release the given c string without freeing it.
      dds_message.@(field.name)_[i]._retn();
    }
  }
@[else]@
  // This causes the DDS::String_mgr to release the given c string without freeing it.
  dds_message.@(field.name)_._retn();
@[end if]@
@[end if]@
@[end for]@

  // some common switch statements in C and C++
  }
}