Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do we use 'this->' and not 'this.' to access members?
    primarykey
    data
    text
    <p>I was looking at a library a person has made for FaceBook in C++. The header file is this:</p> <pre><code>#ifndef __FACEBOOK_H__ #define __FACEBOOK_H__ /** * Facebook Class * Joel Seligstein * Last mod: Aug 22, 2006 * * This is the beginnings of a facebook class set and REST client. Its not documented * yet nor nearly complete. But this is a release to demonstrate its usefulness. * Please email joel@seligstein.com with suggestions or additions. * * TODO: Create classes/parsers for each request type * TODO: Linux URL launcher */ //uncomment to have verbose output turned on //#define fb_debug 1 //define which platform you're compiling for #define fb_windows 1 //#define fb_linux 1 #include &lt;string&gt; #include &lt;sstream&gt; #include &lt;list&gt; using namespace std; #ifdef fb_windows #include &lt;windows.h&gt; #endif #include "curl/curl.h" #include "xmlParser/xmlParser.h" #include "md5.h" class facebook { public: //app/session vars string api_key; string secret; string token; string server; string session_key; string session_secret; string uid; bool has_session; facebook( string my_key, string my_secret, string my_server ); bool authenticate( ); bool request( string method, list&lt;string&gt; params, string *res ); bool load_token( ); void launch_login( string url ); bool get_session( ); void clean_up( ); private: //curl info CURL *curl; CURLcode res; int call_id; //internal functions string get_signature( list&lt;string&gt; params ); static string md5( string str ); static string get_param_string( list&lt;string&gt; params, bool separate ); static size_t write_callback( void *ptr, size_t size, size_t nmemb, void *userp ); }; #endif //__FACEBOOK_H__ </code></pre> <p>Then inside the cpp file, my question is regarding this, the below is the constructor:</p> <pre><code>facebook::facebook( string my_key, string my_secret, string my_server ) { this-&gt;api_key = my_key; this-&gt;secret = my_secret; this-&gt;server = my_server; this-&gt;has_session = false; this-&gt;call_id = 0; } </code></pre> <p>Why have they used the <code>-&gt;</code> operator and not <code>.</code>?</p> <p>I have a limited understanding that <code>-&gt;</code> accesses properties and methods of the type directly in memory but I am confused, I would, through ignorance, expect to see:</p> <pre><code>facebook::facebook( string my_key, string my_secret, string my_server ) { this.api_key = my_key; this.secret = my_secret; this.server = my_server; this.has_session = false; this.call_id = 0; } </code></pre> <p>All I want to know is the theory behind why <code>-&gt;</code> is used over the dot notation.</p> <hr> <p><strong>UPDATE: For anyone else in the same boat as me and learning C++. I have expanded on an example posted by a member in this question. I have also wrapped in initialization list for a member field.</strong></p> <pre><code>#include "stdafx.h" #include &lt;iostream&gt; using namespace std; class A { private: int x; public: A() : x(0){} int getX() const {return x;} void setX(int xx) {x += xx;} }; int main() { A a; a.setX(13); A *pa = &amp;a; pa-&gt;setX(2); A b = a; b.setX(5); cout &lt;&lt; "a" &lt;&lt; a.getX() &lt;&lt; endl; cout &lt;&lt; "a*" &lt;&lt; pa-&gt;getX() &lt;&lt; endl; cout &lt;&lt; "b" &lt;&lt; b.getX() &lt;&lt; endl; return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload