diff options
author | Oskar <[email protected]> | 2024-08-20 13:51:53 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-08-20 13:51:53 +0200 |
commit | 12dda8d5244e86096a5ea56014073dd1892cc409 (patch) | |
tree | ffaf835edd33da23a58405db5e733ebfc71e5a5e /member-access-test.cpp | |
parent | d0c6ac2b68380020d76d7f938307e056a25eb5f5 (diff) |
more
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; +} |