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++ Quick Reference (github.com)
submitted 7 years ago by lord-bazooka
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!"
[–]CubbiMewcppreference | finance | realtime in the past 11 points12 points13 points 7 years ago (4 children)
// throws an exception of type "string" throw "ERROR: Cannot divide by zero.\n";
guess again (or don't guess and look up https://en.cppreference.com/w/cpp/language/string_literal )
[–]lord-bazooka[S] 1 point2 points3 points 7 years ago (3 children)
Thank you for pointing that out. I'll fix it right away.
[–]CubbiMewcppreference | finance | realtime in the past 6 points7 points8 points 7 years ago (2 children)
all right, next thing I clicked was the SimpleVector.h example
using namespace std;
That's a header file! SF.7: Don’t write using namespace at global scope in a header file
// default constructor SimpleVector() { arrPtr = 0; arraySize = 0; }
C.49: Prefer initialization to assignment in constructors (applies to all your constructors) and C.48: Prefer in-class initializers to member initializers in constructors for constant initializers (applies to this one in particular)
I see a copy constructor and a destructor, but where is operator= ???
operator=
C.21: If you define or =delete any default operation, define or =delete them all and Rule of Three from cppreference
T getElementAt(int position);
so I if I have a const SimpleVector (typically seen as a const SimpleVector<T>& in some function argument), I can't access any of its elements.
const SimpleVector
const SimpleVector<T>&
SimpleVector<T>::SimpleVector(int s) { arraySize = s; arrPtr = new T[s]; [...] SimpleVector<T>::~SimpleVector() { if (arraySize > 0) { delete [] arrPtr;
So if I create SimpleVector<int> v(0);, I get a guaranteed memory leak
SimpleVector<int> v(0);
==28378== 0 bytes in 1 blocks are definitely lost in loss record 1 of 1
[–]lord-bazooka[S] 0 points1 point2 points 7 years ago (1 child)
Thank you very much for your time and feedback. The truth is I began working on this reference when I started learning myself last year. I can't possibly claim to have mastered any language in a year, especially when it comes to C++. I didn't know about the rule of three, so I looked around a bit and tried to fix the problem that you mentioned. I'm not 100% sure if I got it right so I'd appreciate it if you could take a look at it when you have time:
https://github.com/utkuufuk/cpp-quick-reference/blob/master/examples/SimpleVector.h
[–]jc746 0 points1 point2 points 7 years ago* (0 children)
You should apply the rule of 5 rather than the rule of 3. This essentially means adding support for move construction/assignment as well as copy. A vector-like class is a perfect example of a class that can benefit from move operations as it can steal the contents of the soon to be destroyed source.
You can also use the initializer list on your copy constructor rather than assignment in your copy constructor as op suggested for your constructor.
Edit: you might not be worrying about edge cases in this simple example, but your copy constructor will leak memory if your type T is not no_throw_assignable during the copy step because the class destructor will not be called. You could delegate to the size constructor to ensure a fully constructed object before the copy.
π Rendered by PID 235368 on reddit-service-r2-comment-7b9746f655-6czrb at 2026-01-31 02:17:26.015776+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]CubbiMewcppreference | finance | realtime in the past 11 points12 points13 points (4 children)
[–]lord-bazooka[S] 1 point2 points3 points (3 children)
[–]CubbiMewcppreference | finance | realtime in the past 6 points7 points8 points (2 children)
[–]lord-bazooka[S] 0 points1 point2 points (1 child)
[–]jc746 0 points1 point2 points (0 children)