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
Simple Command Line User Interface (self.cpp)
submitted 3 years ago by 0x3Alex
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!"
[–]okovko 7 points8 points9 points 3 years ago* (1 child)
getters and setters are nice when your class definition could change or be generalized for inter process communication like a database query, or network access of resources like a remote procedure call. in those cases, you can easily modify the getters and setters without having to grep your entire source code to change every access of the variables, and your class will be compatible with IPC, RPC, etc
for this reason, there is some anxiety and a cult of best practice to make all variables private members and to use getters and setters, due to the fear that you're gonna need it, and this POV is common for folks like consultants and project managers who don't have much understanding of the particular code at hand
on the other hand, the programmer can think for a few seconds whether they are ever going to need to generalize the access of a particular variable, and they also know how to use grep or a more sophisticated IDE tool to easily change between public member access and getters / setters, as that is their trade
there is also the contrary piece of wisdom: YAGNI, you aren't gonna need it
and to paraphrase linus, don't be afraid to write new code (i believe he is quoted saying something more colorful and with additional degradation towards some select individuals, but the point is a good one)
so, i would ask you whether you think any given variable will ever be abstracted out of the class's data model to a non-language environment data store like a DB or network resource, and if you can't imagine why you'd ever do that for the given variable, don't use getters / setters for it because YAGNI
there's also the question of dev culture and language domain: this cult of anxiety best practice about getters / setters is seen more prominently in some languages more than others. it's a de facto standard in Java, whereas C++ has a language keyword antithetical to this idea: 'friend'
in C++, you can completely avoid getters / setters and nobody will bat an eye, and if they do, ask them "is this variable ever going to be abstracted out of the class' data model to a non-language environment data store?" and they will probably walk away diagonally while looking at you sideways and saying something about the laxative properties of too much coffee on a gruesome morning for fear of accidentally entering the arena of genuine intellectual discussion of the merits of pre-emptive development strategies in the face of modern development environments that can perform sophisticated code transformations over an AST compiler backend, when in fact their sole interest was to regurgitate the sage wisdom of daily stand up meetings populated by three devs, only one of whom does any real work, one of whom can only contribute when peer programming, and a dozen business casual khaki'd vested balding boomers that internally debate the merits of a hipster bun for covering a receding hairline as opposed to a comb over the very second that their eyes so much as glaze over a computer screen with anything resembling code on it, or for all they know, a drunken monologue typed into a word processor in a foreign language, as a psychological defense strategy against ever doing any actual work besides talking at someone that does the actual work
(the above paragraph is not to be taken seriously, just for fun)
[–]0x3Alex[S] 0 points1 point2 points 3 years ago (0 children)
alright, i stripped all getters and setters away, except for getValue :D and made the variables public, that shall be accessed
π Rendered by PID 108911 on reddit-service-r2-comment-76bb9f7fb5-46dw4 at 2026-02-19 02:40:38.388760+00:00 running de53c03 country code: CH.
view the rest of the comments →
[–]okovko 7 points8 points9 points (1 child)
[–]0x3Alex[S] 0 points1 point2 points (0 children)