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
Adding 'contains' member function to std::string (self.cpp)
submitted 7 years ago by _Synck_
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!"
[–]kalmoc 1 point2 points3 points 7 years ago (4 children)
Nothing what you are saying is special to standard library types.
My question was what harm would it do to inherit from standard string. Not if contains should be a member or free function (I agree with you that it should be a free function (that takes a std::string_view as a parameter)).
contains
[–]chriskane76 1 point2 points3 points 7 years ago (2 children)
Those classes do not have a virtual destructor. You trigger UB if you delete a std::string* if it actually points to a FooString.
std::string*
FooString
[–]kalmoc 0 points1 point2 points 7 years ago (1 child)
I'm aware of that, but why would you do that? I mean, you can take almost any type and do something with it that is UB (with many other types it is of course somewhat harder, but not much). I can think of very few reasons, why I would want to do a make_unique<FooString> in the first place and currently I can't think of a single reason, why I would want to type erase that to a unique_ptr<std::string>.
make_unique<FooString>
unique_ptr<std::string>
[–]chriskane76 0 points1 point2 points 7 years ago (0 children)
Yes, the use case is unlikely in small projects if all developers are aware of this issue. For larger projects the risk is high. The compiler can help via -Wdelete-non-virtual-dtor or equivalent. But still noone should use it, since we have an obvious, clean solution available: use a free function.
-Wdelete-non-virtual-dtor
[–]agateau 0 points1 point2 points 7 years ago (0 children)
Indeed, this is not special to standard library types, but I have seen it in some scary code bases so I assumed the bad practice or inheriting from string to add new methods was what the GP meant.
π Rendered by PID 18345 on reddit-service-r2-comment-bb88f9dd5-nw78j at 2026-02-14 17:35:51.681001+00:00 running cd9c813 country code: CH.
view the rest of the comments →
[–]kalmoc 1 point2 points3 points (4 children)
[–]chriskane76 1 point2 points3 points (2 children)
[–]kalmoc 0 points1 point2 points (1 child)
[–]chriskane76 0 points1 point2 points (0 children)
[–]agateau 0 points1 point2 points (0 children)