diff options
Diffstat (limited to 'member-access-test.cpp')
-rw-r--r-- | member-access-test.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/member-access-test.cpp b/member-access-test.cpp new file mode 100644 index 0000000..aeede89 --- /dev/null +++ b/member-access-test.cpp @@ -0,0 +1,22 @@ +#include <iostream> + +/* + * + * + * + * + */ + +int main () { + + std::string s1 = "a string"; + std::string *p = &s1; + auto n1 = s1.size(); // Call size member function (method) on s1 + auto n2 = p->size(); // same thing but p is dereferenced and then call size member function (method) on s1 + auto n3 = (*p).size(); // same thing as above but without using '->' operator + + std::cout << n1 << " " + << n2 << " " + << n3 << " " << std::endl; + return 0; +} |