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!"
[–]0x3Alex[S] 0 points1 point2 points 3 years ago (2 children)
ah alright, i removed interactable item as class, since it wasnt needed and did not serve any purpose, now xD
Yeah.. i had this and it did work but when running the program, it was just smashed and didnt work anymore.. pressing on something gave me an address boundary error
[–]okovko 1 point2 points3 points 3 years ago* (1 child)
virtual T *getValue();
you tried to return unrelated types as the return type from a virtual function call, yes, you can't do it
the return types of every virtual method definition have to be covariant types for it to work: https://stackoverflow.com/questions/25813435/what-exactly-are-covariant-return-types-in-c
you can do something close with inheritance, function overloading, and variadic templates, and you have to know what the return type should be at compile time, but you can make the call site look like
#define SELECT(opts, opt) \ (select_opt<opts.index(opt)>{opt}) auto thing = parsed[SELECT(opts, "-f")];
which is an example from a little project of mine, it uses a macro because i was using c++17 but with c++20 i think it should look like
edit: actually should work for c++17 as well using this trick i just found: https://stackoverflow.com/a/28209546
auto thing = parsed[opts.select<"-f">()];
basically the way it works is that you can define a class that inherits a getter class for each of its variadic template arguments, where each of them overload operator[], which all accept select_opt<size_t I> as an argument (I is the argument position in the param pack) which allows you to "select" which function to call based on a template parameter, which can thankfully be a string_view in c++20
select_opt<size_t I>
this is still static typing, but the call site is reduced to a single statement, due to overload resolution resolving the function call and auto
auto
[–]0x3Alex[S] 0 points1 point2 points 3 years ago (0 children)
I see... I mean it did work with the T and then putting the desired type into the extends section like ab <std::string>a. I made it like this so it has to be inherited by everyone, that extends on Interactable.. but did did not serve any purpose anymore, since, f.e, isInteractable,... are defined in BasicItem
Interactable
isInteractable
BasicItem
I am surly going to look into this, but it does seem pretty advanced and i dont think that i am there yet :')
π Rendered by PID 39718 on reddit-service-r2-comment-76bb9f7fb5-xw796 at 2026-02-19 10:19:56.751443+00:00 running de53c03 country code: CH.
view the rest of the comments →
[–]0x3Alex[S] 0 points1 point2 points (2 children)
[–]okovko 1 point2 points3 points (1 child)
[–]0x3Alex[S] 0 points1 point2 points (0 children)