免费爱碰视频在线观看,九九精品国产屋,欧美亚洲尤物久久精品,1024在线观看视频亚洲

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

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

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

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

      本文主要分以下幾個部分:

      • ROS 2 Humble – C++ Publisher node 代碼
      • ROS 2 Humble – C++ Subscript node 代碼
      • C++ 與 C語言的區(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語言的區(qū)別

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

      1 介紹

      C 由 Dennis Ritchie 于 1969 年左右在 AT&T 貝爾實驗室開發(fā)。

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

      2 語言類型

      C 是過程編程。

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

      3 OOP 功能支持

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

      C++ 支持多態(tài)、封裝和繼承,因為它是一種面向?qū)ο蟮木幊陶Z言

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

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

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

      5 驅(qū)動型

      C 一般稱為函數(shù)驅(qū)動語言。

      C++ 被稱為對象驅(qū)動語言。

      6 支持的功能

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

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

      以下是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

      今天就介紹到這里。

      接下來打算再介紹一下Python3編程的基礎知識,關(guān)于ROS 2接下來的實戰(zhàn)介紹,以后有機會再一點點介紹。

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

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

      參考資料:

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

      相關(guān)推薦

      • 存儲過程語法(sql server存儲過程語法)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        2022年11月24日

      聯(lián)系我們

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