在线不卡日本ⅴ一区v二区_精品一区二区中文字幕_天堂v在线视频_亚洲五月天婷婷中文网站

  • <menu id="lky3g"></menu>
  • <style id="lky3g"></style>
    <pre id="lky3g"><tt id="lky3g"></tt></pre>

    「DG數(shù)據(jù)圈聊ROS 2 Humble」EP27: C++與C的區(qū)別

    機(jī)器人操作系統(tǒng)ROS 2 Humble中可以通過(guò)使用C++編寫收發(fā)程序。消息的發(fā)送和接受,讓不同組件間的消息傳遞成為可能,通過(guò)獲取消息,對(duì)環(huán)境以及執(zhí)行指令進(jìn)行了解,機(jī)器人就會(huì)明確下一步的行為。

    這里給出ROS 2 Humble C++消息收發(fā)程序的實(shí)例代碼, 然后介紹一個(gè)C++與C的區(qū)別列表

    想了解C的小伙伴,可以看看我之前的系列文章: 「DG數(shù)據(jù)圈聊ROS 2 Humble」EP21 到 EP26.

    本文主要分以下幾個(gè)部分:

    • ROS 2 Humble – C++ Publisher node 代碼
    • ROS 2 Humble – C++ Subscript node 代碼
    • C++ 與 C語(yǔ)言的區(qū)別

    ROS 2 Humble – C++ Publisher node 代碼

    #include #include #include #include #include “rclcpp/rclcpp.hpp”#include “std_msgs/msg/string.hpp”using namespace std::chrono_literals;/* This example creates a subclass of Node and uses std::bind() to register a* member function as a callback from the timer. */class MinimalPublisher : public rclcpp::Node{ public: MinimalPublisher() : Node(“minimal_publisher”), count_(0) { publisher_ = this->create_publisher(“topic”, 10); timer_ = this->create_wall_timer( 500ms, std::bind(&MinimalPublisher::timer_callback, this)); } private: void timer_callback() { auto message = std_msgs::msg::String(); message.data = “Hello, world! ” + std::to_string(count_++); RCLCPP_INFO(this->get_logger(), “Publishing: ‘%s'”, message.data.c_str()); publisher_->publish(message); } rclcpp::TimerBase::SharedPtr timer_; rclcpp::Publisher::SharedPtr publisher_; size_t count_;};int main(int argc, char * argv[]){ rclcpp::init(argc, argv); rclcpp::spin(std::make_shared()); rclcpp::shutdown(); return 0;}

    ROS 2 Humble – C++ Subscript node 代碼

    #include #include “rclcpp/rclcpp.hpp”#include “std_msgs/msg/string.hpp”using std::placeholders::_1;class MinimalSubscriber : public rclcpp::Node{ public: MinimalSubscriber() : Node(“minimal_subscriber”) { subscription_ = this->create_subscription( “topic”, 10, std::bind(&MinimalSubscriber::topic_callback, this, _1)); } private: void topic_callback(const std_msgs::msg::String & msg) const { RCLCPP_INFO(this->get_logger(), “I heard: ‘%s'”, msg.data.c_str()); } rclcpp::Subscription::SharedPtr subscription_;};int main(int argc, char * argv[]){ rclcpp::init(argc, argv); rclcpp::spin(std::make_shared()); rclcpp::shutdown(); return 0;}

    C++ 與 C語(yǔ)言的區(qū)別

    先介紹一下C++ 與 C的6大主要區(qū)別,然后會(huì)給出一個(gè)詳細(xì)的列表。

    1 介紹

    C 由 Dennis Ritchie 于 1969 年左右在 AT&T 貝爾實(shí)驗(yàn)室開(kāi)發(fā)。

    C++ 由 Bjarne Stroustrup 于 1979 年開(kāi)發(fā)。

    2 語(yǔ)言類型

    C 是過(guò)程編程。

    C++ 支持過(guò)程和面向?qū)ο蟮木幊谭妒健?/p>

    3 OOP 功能支持

    由于 C 不支持 OOP 概念,因此它不支持多態(tài)性、封裝和繼承。

    C++ 支持多態(tài)、封裝和繼承,因?yàn)樗且环N面向?qū)ο蟮木幊陶Z(yǔ)言

    4 數(shù)據(jù)安全

    由于 C 不支持封裝,因此數(shù)據(jù)表現(xiàn)為自由實(shí)體,可以由外部代碼操作。

    C++可通過(guò)封裝隱藏?cái)?shù)據(jù),以確保按預(yù)期使用數(shù)據(jù)結(jié)構(gòu)和運(yùn)算符。

    5 驅(qū)動(dòng)型

    C 一般稱為函數(shù)驅(qū)動(dòng)語(yǔ)言。

    C++ 被稱為對(duì)象驅(qū)動(dòng)語(yǔ)言。

    6 支持的功能

    C 不支持函數(shù)和運(yùn)算符重載,也沒(méi)有命名空間功能和引用變量功能。

    C++ 支持函數(shù)和運(yùn)算符重載,還具有命名空間功能和引用變量功能。

    以下是softwaretestinghelp給出的C與C++具體區(qū)別列表:

    No

    Characteristics

    C

    C++

    1

    Type of programming

    Procedural language

    Object-Oriented programming language.

    2

    Programming Approach

    Top-down approach

    Bottom-up approach

    3

    Application development

    Good for embedded devices, system-level coding etc.

    Good for networking, server-side applications, gaming, etc.

    4

    File Extension

    .c

    .cpp

    5

    Compatibility with each other

    Not Compatible with C++.

    Compatible with C as C++ is a subset of C.

    6

    Compatibility with other languages

    Not compatible

    Compatible

    7

    Ease of coding

    Allows us to code everything.

    Comes with highly advanced Object-Oriented concepts.

    8

    Data Security

    Negligible

    High

    9

    Program pision

    Program pided into functions.

    Program pided into classes and objects.

    10

    Standard I/O operations

    scanf/printf

    cin/cout

    11

    Focus/emphasis

    Emphasizes on functions and/or processes.

    Emphasizes on data rather than functions.

    12

    The main() function

    Can call main through other functions.

    Not possible to call main from any point.

    13

    Variables

    To be declared at the beginning of the function.

    Can be declared anywhere in the program.

    14

    Global variables

    Multiple declarations

    No multiple declarations.

    15

    Reference Variables and pointers

    Only Pointers

    Both

    16

    Enumerations

    Only integer types.

    Distinct type

    17

    Strings

    Supports only char[]

    Supports string class which is immutable.

    18

    Inline function

    Not supported

    Supported

    19

    Default arguments

    Not supported

    Supported

    20

    Structures

    Cannot have functions as structure members.

    Can have functions as structure members.

    21

    Classes and Objects

    Not supported

    Supported

    22

    Data Types

    Only built-in and primitive data types are supported. No Boolean and string types.

    Boolean and string types supported in addition to built-in data types.

    23

    Function overloading

    Not supported

    Supported

    24

    Inheritance

    Not supported

    Supported

    25

    Functions

    Does not support functions with default arrangements.

    Supports functions with default arrangements.

    26

    Namespace

    Not supported

    Supported

    27

    Source code

    Free-format

    Originally taken from C plus object-oriented.

    28

    Abstraction

    Not present

    Present

    29

    Information hiding

    Not supported

    Supported

    30

    Encapsulation

    Not supported

    Supported

    31

    Polymorphism

    Not supported

    Supported

    32

    Virtual function

    Not supported

    Supported

    33

    GUI programming

    Using the Gtk tool.

    Using the Qt tools.

    34

    Mapping

    Cannot easily map data and functions.

    Data and functions can be easily mapped.

    35

    Memory management

    Malloc(), calloc(), free() functions.

    New() and delete() operators.

    36

    Default headers

    Stdio.h

    iostream header

    37

    Exception/error handling

    No direct support.

    Supported

    38

    Keywords

    Supports 32 keywords.

    Supports 52 keywords.

    39

    Templates

    Not supported

    Supported

    今天就介紹到這里。

    接下來(lái)打算再介紹一下Python3編程的基礎(chǔ)知識(shí),關(guān)于ROS 2接下來(lái)的實(shí)戰(zhàn)介紹,以后有機(jī)會(huì)再一點(diǎn)點(diǎn)介紹。

    歡迎點(diǎn)贊關(guān)注哦。

    本文作者:頭條號(hào)DG數(shù)據(jù)圈,公眾號(hào)德國(guó)數(shù)據(jù)圈

    參考資料:

  • https://docs.ros.org/en/humble/Tutorials/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html
  • https://www.tutorialspoint.com/difference-between-c-and-cplusplus
  • https://www.softwaretestinghelp.com/c-vs-cpp/
  • https://softwareengineering.stackexchange.com/questions/113295/when-to-use-c-over-c-and-c-over-c
  • 鄭重聲明:本文內(nèi)容及圖片均整理自互聯(lián)網(wǎng),不代表本站立場(chǎng),版權(quán)歸原作者所有,如有侵權(quán)請(qǐng)聯(lián)系管理員(admin#wlmqw.com)刪除。
    用戶投稿
    上一篇 2022年6月17日 21:07
    下一篇 2022年6月17日 21:09

    相關(guān)推薦

    • 存儲(chǔ)過(guò)程語(yǔ)法(sql server存儲(chǔ)過(guò)程語(yǔ)法)

      今天小編給各位分享存儲(chǔ)過(guò)程語(yǔ)法的知識(shí),其中也會(huì)對(duì)sql server存儲(chǔ)過(guò)程語(yǔ)法進(jìn)行解釋,如果能碰巧解決你現(xiàn)在面臨的問(wèn)題,別忘了關(guān)注本站,現(xiàn)在開(kāi)始吧! oracle存儲(chǔ)過(guò)程基本語(yǔ)法…

      2022年11月26日
    • 劉畊宏回應(yīng)梅西輸球后哭了:跳操流汗到眼睛 剛好有點(diǎn)流鼻水

      11月23日,劉畊宏發(fā)言回應(yīng)自己再梅西輸球后流淚的消息,他寫道:“我是有些難過(guò)… 然后…跳操流汗到眼睛,剛好有點(diǎn)流鼻水,阿根廷之后的比賽會(huì)贏的!”據(jù)悉,11月22日的世界杯比賽中,…

      2022年11月26日
    • EDG粉絲酸了!JDG重磅官宣,頂級(jí)打野Kanavi留在LPL賽區(qū)

      2022英雄聯(lián)盟職業(yè)聯(lián)賽冬季轉(zhuǎn)會(huì)期已經(jīng)于11月22日拉開(kāi)帷幕,在轉(zhuǎn)會(huì)期首日作為L(zhǎng)PL觀眾關(guān)注的焦點(diǎn)的JDG戰(zhàn)隊(duì),就官宣了Yagao離隊(duì)以及Homme續(xù)約的消息,這讓人十分意外。畢竟…

      2022年11月25日
    • 全民K歌升級(jí)新版本7.0之后,有哪些隱藏功能?

      作者:高百烈來(lái)源:知乎 這個(gè)功能,舊版并沒(méi)有,要升級(jí)到全新的全民K歌7.0版本才能發(fā)現(xiàn)。 作為朋友圈當(dāng)代K歌之王,我費(fèi)了不少功夫才搶到內(nèi)測(cè)版本。有一說(shuō)一,全民K歌的路子真的很野,新…

      2022年11月25日
    • 上手Reno8 Pro體驗(yàn)跨屏互聯(lián) 實(shí)在太方便!

      11月已經(jīng)來(lái)到了月底,在手機(jī)品牌又要推出新一年度的新品手機(jī)之前,我們來(lái)點(diǎn)評(píng)一下今年令人驚喜的產(chǎn)品。如OPPO的Reno8 Pro系列,該系列搭載雙芯影像配置獲得了很多消費(fèi)者的認(rèn)可?!?/p>

      2022年11月25日
    • 什么是推廣cpa一篇文章帶你看懂CPA推廣渠道

      CPA渠道 CPA指的是按照指定的行為結(jié)算,可以是搜索,可以是注冊(cè),可以是激活,可以是搜索下載激活,可以是綁卡,實(shí)名認(rèn)證,可以是付費(fèi),可以是瀏覽等等。甲乙雙方可以根據(jù)自己的情況來(lái)定…

      2022年11月25日
    • 賈乃亮的消息的最新動(dòng)態(tài)(賈乃亮終于又宣布好消息)

      本以為賈乃亮與李小璐官宣離婚后的畫風(fēng),該是“一別兩寬,各生歡喜”。 誰(shuí)知卻是“剪不斷,理還亂”,八卦傳聞比離婚前還多。 最近,就有不少新聞報(bào)道稱,賈乃亮和李小璐又決定為了女兒復(fù)合?!?/p>

      2022年11月25日
    • 抖音直播帶貨有哪些方法技巧(抖音直播帶貨有哪些痛點(diǎn))

      如今抖音這個(gè)短視頻的變現(xiàn)能力越來(lái)越突顯了,尤其是在平臺(tái)上開(kāi)通直播,更具有超強(qiáng)的帶貨屬性,已經(jīng)有越來(lái)越多的普通人加入到其中了。不過(guò)直播帶貨雖然很火,但是也不是每個(gè)人都能做好的,那么在…

      2022年11月24日
    • 不止《阿凡達(dá)》 網(wǎng)傳海賊王新電影《RED》引進(jìn)大陸:12月1日上映

      11月23日消息,20世紀(jì)影業(yè)官方正式宣布《阿凡達(dá)2:水之道》中國(guó)內(nèi)地正式定檔,12月16日同步北美上映。 好消息不止一個(gè),據(jù)博主“海賊王公會(huì)”爆料:海賊王新劇場(chǎng)版《RED》,中譯…

      2022年11月24日
    • 《熊出沒(méi)·伴我“熊芯”》2023年春節(jié)上映喜迎新年

      預(yù)告片在線觀看 熊出沒(méi)來(lái)了,歡樂(lè)就來(lái)了,團(tuán)圓年就來(lái)了!“熊出沒(méi)”系列第九部電影《熊出沒(méi)·伴我“熊芯”》今日發(fā)布首支預(yù)告和海報(bào),計(jì)劃于2023年春節(jié)上映。作為每年必備的“年貨”,“春…

      2022年11月24日

    聯(lián)系我們

    聯(lián)系郵箱:admin#wlmqw.com
    工作時(shí)間:周一至周五,10:30-18:30,節(jié)假日休息