Anonymous
I was asked in an interview, say i need to create a new object of the concrete type to which the base pointer points to. How to do that ? I gave 2 obvious options of dynamic_cast and typeid but he said both will need if-else. Any one know of any other method ?
You need to use polymorphism. Create a virtual method called clone which returns a unique_ptr<Base> in the base class and a unique_ptr<Derived> in the derived class. So if you use a pointer or a reference to the base to call the clone method, the correct virtual method will be called depending on the object being pointed to.
Anonymous
You can read books about functional programming, they will help you to better understand some functional design patterns including recursion.
??? Functional programming uses recursion as a very basic tool. There are more advanced concepts in functional programming than recursion like monoids, monads, functors, ADTs and so on many of which actually dont require recursion and can be implemented using pattern matching on type/data constructors and composition. Asking someone to study functional programming to learn recursion is like asking someone trying to understand how a while loop in python works to learn C++.
Artur
In the main ? You don’t but it’s a good practise to write return something
Pavel
That's actually an interesting question, do people generally return 0 from main or not
Moouuaaddhh
Pavel
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f46-int-is-the-return-type-for-main
Pavel
To anywhere outside MSVC
Moouuaaddhh
I use gcc/g++ it works fine
Pavel
I use gcc/g++ it works fine
It doesn't compile for me 🤷‍♂️ https://wandbox.org/permlink/ScknknFlZYgRWe9T
\Device\NUL
No it's not int main(void) { } Compile with -pedantic-errors, it wouldn't compile
Pavel
No it's not int main(void) { } Compile with -pedantic-errors, it wouldn't compile
What compiler do you use? Both GCC and clang compile it for me with this flag https://wandbox.org/permlink/IRalLucHWwaI1DDt
\Device\NUL
I think the compiler wont compile if it void main() or missing return type. It's not empty main() func
\Device\NUL
No, that's the standard
\Device\NUL
You should check if it standards or not with pedantic flag
\Device\NUL
main function should return int.
\Device\NUL
Of course GCC will compile also but it also generates warn
Pavel
MSVC just were adding stuff to their compiler that allowed some incorrect code to compile or work
Pavel
volatile
布丁
the main function is actually an exception in C11
布丁
not returning anything from int main implies return 0, as C11 standard implies
\Device\NUL
Thanks for the information
布丁
Doesn’t apply to anything else, including WinMain
\Device\NUL
but it generates warn
pavel
Not in msvc. But not sure about standard
Anonymous
How can I declare an "extern" full specialization of function template in header file?
Your question is confusing. Do you want to generate a specific instantiation in one translation unit and mark it as extern in a header file to prevent instantiations in other translation units? Or do you want to write a specialization for specific types for your function template? When you specialize, you cant mark it as an extern template elsewhere.
Madacaos
🤔
Madacaos
I would be very grateful if you help me, find my problem in the Daysandbox report (-> ???)
klimi
I would be very grateful if you help me, find my problem in the Daysandbox report (-> ???)
Hello! I'm quite new to the world of C. I should compile a repository found on github but I can not configure the codeblocks compiler, the developer in read.md said that it uses the compiler "mingw-7.3.0", I tried to use the automatic installation provided in the installations of codeblocks, to manually install the compiler and declare the files in the toolchain but unfortunately I did not produce any results
klimi
(it treats read.md as link)
Hussein
compile it makefiles
but I guess you have to install gnu make on windows, there is a way to do so but I don’t remember how
Hussein
sorry never used windows for years now
Anonymous
cmake is a useful tool to replace Makefile
Anonymous
wsl works
Hussein
cmake is a useful tool to replace Makefile
yeah but it’s bloated and more complicated plus make files are almost in every repo but cmake files aren’t as popular
Hussein
WSL
yeah wsl is a lot easier programming in c on windows is horrible
Hussein
tbh it is cross-platform so you can use it on machines other than Unix-like/based systems
Hussein
disagree
it is really about preference some people even use ninija builds for some reason
Hussein
Ninja is just generator. It can be used with cmake
I didn’t know that I use only make for my projects and cmake for repos that I try to compile from scratch
pavel
while make force you use system depended utils
Hussein
cmake is very mature and defacto standard for c/cpp
only if you using it on windows it is not a standard on GNU systems
pavel
only if you using it on windows it is not a standard on GNU systems
cmake? it's cross-platform. you can use it everywhere. personally me compile the same project on windows/ubuntu/android. windows/STM32
Hussein
you are right CMake is less especially when programming in C on Unix maybe because it is relatively new compared to Make which appeared in 1979
Hussein
so when GNU guys made all their software built with make (because that was what they implemented back then)
pavel
legacy
Hussein
so not a lot of their projects support cmake which is almost everything you might use on a modren linux machine today
pavel
Just use cmake for new projects)
Hussein
I just check it out on wikipedia cmake actually generates makefiles on unix-like system
Pavel
I just check it out on wikipedia cmake actually generates makefiles on unix-like system
You can configure it to do that, I think nowadays it generates ninja projects by default
pavel
I just check it out on wikipedia cmake actually generates makefiles on unix-like system
Sure. Make by default. Or ninja. As well as on windows vcxproj for msvc or make and ninja
Pavel
No. Ninja have some problems with mulicore building
Maybe, but it's default at least as far as I can see
ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
https://pastebin.com/prfzZs5u if anyone could please help explain why anytime i try to generate a random number through this Dice class, i get the same values (even though its been seeded).
ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
https://pastebin.com/prfzZs5u if anyone could please help explain why anytime i try to generate a random number through this Dice class, i get the same values (even though its been seeded).
i created 2 objects from the class to generate random numbers but anytime i run the program they produce same numbers. I've tried to generate random numbers without the class and it works fine.
Lev
what online communities for the C language exist
Lev
BullShit С
\Device\NUL
cmake? nope
https://suckless.org/sucks/
pavel
https://suckless.org/sucks/
fun but much of topics just a hate
Dima
https://suckless.org/sucks/
why there are no python or js libs