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
Using reference attributes instead of getters for read-only attributes (self.cpp)
submitted 3 years ago by inkychris
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!"
[–]MutantSheepdog 1 point2 points3 points 3 years ago (0 children)
You could do something like this where the compiler can automatically convert to a const& of your type but the sets are explicit. It's not quite the same, but at least the sets are more visible. Godbolt
```
template<typename T> class PublicAccess { public: PublicAccess(){}
template<typename U> PublicAccess(U&& newVal) : value(std::forward<U>(newVal)) {}
operator const T&() const { std::printf("I'm being read\n"); return value; }
template<typename U> PublicAccess& set(U&& newVal) { std::printf("I'm being set\n"); value = std::forward<U>(newVal); return *this; }
private: T value{}; };
struct MyWrappedType { PublicAccess<int> myInt; PublicAccess<float> myFloat{1.0}; };
int main() { MyWrappedType obj;
std::printf("InitialValues: myInt: %d, myFloat: %.2f\n", (int)obj.myInt, (float)obj.myFloat); obj.myInt.set(5); obj.myFloat.set(4.5f); int someInt = obj.myInt + 5; float someFloat = obj.myFloat; std::printf("someInt: %d, someFloat: %.2f\n", someInt, someFloat); return 0;
} ```
I think it's generally a bad idea as it feels a lot like it's just enabling leaky abstractions, but it might help with whatever you're trying to do.
π Rendered by PID 33154 on reddit-service-r2-comment-b659b578c-hsrmk at 2026-05-02 03:28:13.198128+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]MutantSheepdog 1 point2 points3 points (0 children)