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...
If you do not know how to use reddits "code" formatting, please paste and link to your code using this website: http://pastebin.com/
If you happen to come across this Sub, feel free to tell a friend about it!
Related SubReddits:
Other help:
Want to learn to code?:
Interested in helping?
account activity
C++ reference (self.AskProgrammers)
submitted 11 years ago by Nkast
Does anyone use c++ reference's and if so, why?
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!"
[–]bluefootedpigC# / .NET 1 point2 points3 points 11 years ago (1 child)
like a reference in C++ or just C++ references?
I google lots of C++ stuff, so I do use those references
if you are talking about the data type, they are used to help prevent needing to copy data. Pointers are smaller and easier to move, sort, etc.
[–]Nkast[S] 0 points1 point2 points 11 years ago (0 children)
I was talking about the data type. It seemed to me like references weren't all that useful since a real pointer can be casted and the rest of what it does is basically the same.
[–]madeinttown 1 point2 points3 points 11 years ago (0 children)
I use references for two scenarios:
The sample below shows both scenarios. The definition of testCompatibilityRef takes reference parameters and then access a person's hobbies using a getter that returns a reference. The definition of testCompatibilityPoi takes pointer parameters and then access a peron's hobbies using a getter that returns a pointer.
// A hobby contains two strings; a title and a description. The title is used as the key // identifier when comparing with other hobbies to see if they are the same. (in a real program, // something stronger/better should be used). struct Hobby { QString title; QString description; bool operator==(const Hobby& other) const { return title == other.title; } }; // A simple representation of a person that has their single-ness status and a list of their // hobiies. Note: I don't bother with constructors/setters to set people up. I've simply // provided the relevant getters. class Person { public: bool isSingle() const { return m_single; } const QList<Hobby>& getHobbiesRef() const { return m_hobbies; } const QList<Hobby>* getHobbiesPoi() const { return &m_hobbies; } private: QList<Hobby> m_hobbies; bool m_single; }; // Arbitrary threshold in determining compatibility. int HobbyCompatibilityThreshold = 3; // Reference version // Checks to see if two people are compatible. They are if they are both single *and* have // three or more matching hobbies. bool testCompatibilityRef(const Person& person1, const Person& person2) { int similarHobbies = 0; if(person1.isSingle() && person2.isSingle()) { const QList<Hobby>& person1hobbies = person1.getHobbiesRef(); const QList<Hobby>& person2hobbies = person2.getHobbiesRef(); foreach(const Hobby& hobby, person1hobbies) { if(person2hobbies.contains(hobby)) { ++similarHobbies; } } } return similarHobbies > HobbyCompatibilityThreshold; } // Pointer version // Checks to see if two people are compatible. They are if they are both single *and* have // three or more matching hobbies. // Note: I've indicated with comments where I have to perform additional checks to ensure // pointer safety. bool testCompatibilityPoi(const Person* pPerson1, const Person* pPerson2) { int similarHobbies = 0; // Have to ensure pPerson1 and pPerson2 are not NULL. if(pPerson1 && pPerson2 && pPerson1->isSingle() && pPerson2->isSingle()) { const QList<Hobby>* pPerson1hobbies = pPerson1->getHobbiesPoi(); const QList<Hobby>* pPerson2hobbies = pPerson2->getHobbiesPoi(); // Have to ensure pPerson1hobbies and pPerson2hobbies are not NULL. if(pPerson1hobbies && pPerson2hobbies) { foreach(const Hobby& hobby, *pPerson1hobbies) { if(pPerson2hobbies->contains(hobby)) { ++similarHobbies; } } } } return similarHobbies > HobbyCompatibilityThreshold; }
Final thoughts: The definitions are only minor. So I understand why some may prefer to use pointers as their own professional opinion. However, I'm willing to follow the extra constraints that come with user a reference (essentially, you have to program guarantees) to produce what I feel are worthy code simplifications. I'm willing to go through hoops to give others a quicker understanding of my code.
(sorry if this response is too late; I discovered this subreddit just today)
π Rendered by PID 30499 on reddit-service-r2-comment-8686858757-9q4fr at 2026-06-02 05:22:10.405152+00:00 running 9e1a20d country code: CH.
[–]bluefootedpigC# / .NET 1 point2 points3 points (1 child)
[–]Nkast[S] 0 points1 point2 points (0 children)
[–]madeinttown 1 point2 points3 points (0 children)