C中的箭头成员运算符

我很擅长使用C语言.我以前处理过 Java和ActionScript,但现在我想学习这种强大的语言.由于C授予程序员显式使用指针的能力,因此我对使用箭头成员运算符感到困惑.这是我尝试编写的示例代码.

main.cpp中:

#include <iostream>
   #include "Arrow.h"
   using namespace std;

   int main()
   {
        Arrow object;
        Arrow *pter = &object;

        object.printCrap(); //Using Dot Access
        pter->printCrap(); //Using Arrow Member Operator
        return 0;
   }

Arrow.cpp

#include <iostream>
   #include "Arrow.h"
   using namespace std;

   Arrow::Arrow()
   {

   }

   void Arrow::printCrap(){
       cout << "Steak!" << endl;
   }

在上面的代码中,它所做的只是使用两种方法(Dot和Arrow)打印牛排.

简而言之,在使用C编写实际应用程序时,何时使用箭头符号?由于我以前的编程经验,我习惯使用点符号,但箭头对我来说是全新的.

解决方法

好问题,

Dot(.) this operator is used for accessing the member function or
sometime the data member of a class or structure using instance
variable of that class/Structure.

object.function(); 
object.dataMember; //not a standard for class.

arrow(->) this operator is used for accessing the member function or
sometime the data member of a class or structure but using pointer of
that class/Structure.

ptr->function();
ptr->datamember; //not a standard for class.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...