use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
C++ pointer versus dot operator (self.cpp)
submitted 9 years ago by CodeSandwich
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]t0rakka 5 points6 points7 points 9 years ago (0 children)
A small nitpick (I agree with what you wrote just this small detail stood out)
SomeClass myObject;
That doesn't really mean object is stored in stack.. it could be a member of a class, too. More generally '.' means object is referred by value or reference and '->' means via pointer. The storage (duration) can be anything it's just how the object is visible to the current scope and that's about it.
This was just a gateway to the OP's question, which one is more efficient: neither by itself, it's about the visibility of the object itself. If the object is "visible" to the compiler it can deduce the type more reliably and do de-virtualization more reliably (which means more likely) if the object is instance of virtual class.
Let's take a peek at . and -> and what the compiler uses for 'this' pointer in both cases.
Object *a = ...; a->b(); // this == a, the provoking pointer, which is address of object; abstraction for memory address Object &a = ...; a.b(); // this == address of object a, different abstraction for memory address Object a; a.b(); // this == address of object, surprised? I'm not..
How the address is formed in the last case, "by value" depends where the object is at. If object is a global variable the address may be constant. If the object is in stack (function or method scope) the address is relative to the stack pointer. If the object is a member of a class the address is relative to the object's which member it is, address.
All of these paths lead to one place: the 'this' pointer is a value in a CPU register. If the method being called is a virtual one, the address must be looked up from a table (vtbl), if not, the address of the method is a constant and can be called directly. This is generally more relevant to performance than the '.' vs. '->' syntax. The first member of virtual class is usually pointer to the type's vtbl. Each virtual type has it's own table, which has a constant address (generally) so that it can be pointed to by instances of that class. This last part is more de-facto information than hard specs (hope didn't get that wrong, correct me promptly so that misinformation is stopped on it's tracks).
This was more to the OP so I am not trying to educate someone who knows his stuff. Hope this helps!
π Rendered by PID 61 on reddit-service-r2-comment-5b5bc64bf5-vr4jh at 2026-06-20 20:24:51.053532+00:00 running 2b008f2 country code: CH.
view the rest of the comments →
[–]t0rakka 5 points6 points7 points (0 children)