In order to be able to pass function as a parameter I had to #include
@damianrivas5 жыл бұрын
And you should be. Idk how he has his IDE set up so that he doesn't need to include headers from the standard library, but you should always #include the parts of the standard library that you're using. You wouldn't use std::vector without #include
@hamoudy413 жыл бұрын
@@damianrivas The screen shows from line number 5 so it is quite possible that they are included but they cannot be seen on the screen.
@jonathany12402 жыл бұрын
@@hamoudy41 Idk about in the past but currently Derek has a link to all his code transcripts and i've noticed they routinely miss out on necessary libraries. idk if this is just netbeans versions or something beyond my beginner understanding but it's great that the comments are here to quickly fix what ever's wrong.
@paolodepetris70343 жыл бұрын
a more 'std' way to generate a vector of heads/tails (or any vector of random numbers): std::mt19937 rng(std::random_device{}()); std::uniform_int_distribution d(0, 1); std::generate_n(std::back_inserter(your_vector), N, [&]() { return d(rng); }); where N is the size of the vector
@jakekudur22636 жыл бұрын
Hi Derek! make tutorial for BFS, DFS, Minimum Spanning Tree. Prim's Algorithm, Bellman-Ford Algorithm and such other algorithms, pls
@chiragpanchalreadytorock4 жыл бұрын
ChangeList could be written using auto as follows :- auto changeList(std::vector& v, std :: function) -> typename std::remove_reference::type {...} Though I prefer what is being showed here....
@Tornnaz5 жыл бұрын
i got it right! thanks for the help. decided to learn c++ today and im already picking up speed. ive coded in other languages before though, so im not exactly new to this.
@derekbanas5 жыл бұрын
Happy I could help
@DivusMeta6 жыл бұрын
I found it clear this way, since the we are doing basically filtering. ``` bool isOdd(int num) { return num % 2 == 1; } std::vector changeList(std::vector numList, std::function func) { std::vector result; std::copy_if(numList.begin(), numList.end(), std::back_inserter(result), func); return result; } ```
@worldshaper17233 жыл бұрын
You have no idea. how much you have helped me.
@ironclownfish22 жыл бұрын
bool IsItOdd(int num) { return num & 1; }
@gunnaryoung4 жыл бұрын
Thank you, awesome video! I'm not even two minutes in and I've already figured out how to solve a problem that has been my brick wall for weeks.
@derekbanas4 жыл бұрын
That's great! Happy I could help
@RanVargas5 жыл бұрын
This was really helpful, I was finally able to grasp the concept behind the functions.
@derekbanas5 жыл бұрын
I'm happy I could help :)
@edwardchen65796 жыл бұрын
I couldn’t believe that so many Computer Language Tutorials are made by yourself!! How could you learn so many languages??I only learnt C and C++,and I’m learning Python using my raspberrypi0w,and I’m planning to learn Assembly on ARM by watching your Assembly Tutorial videos. Nice Job!
@derekbanas6 жыл бұрын
Thank you very much :) After you learn a few languages its pretty easy to learn any of them
@edwardchen65796 жыл бұрын
yes!I can feel that when I'm learning Python,I just took 8 days,and I have learnt most content. And, will you finish Assembly Tutorial Vedios?That will be a great help to me.Thanks again.(PS: your speaking speed is a little fast to me, sometimes I have to listen twice or more, my poor English,LOL)
@SuperSlugger946 жыл бұрын
Hello Derek, great tutorial series! I just have a question. When you have a function returning a boolean, why do you write, for example: if(num % 2 == 0){ return true; }else{ return false; } Instead of just writing: return (num % 2 == 0);
@derekbanas6 жыл бұрын
You could do that. I tend to be verbose in tutorials
@vivekpanchagnula8155 жыл бұрын
he wanted everyone to understand what the program did. in an actual program, i doubtd he do that
@2271masoud6 жыл бұрын
I've always enjoyed watching your videos and this one is not an exception, I've got a lot to do SO LET'S GET INTO IT. Thanks Derek
@derekbanas6 жыл бұрын
Thank you :) I have no idea where I got those catch phrases from?
@romuloromero8865 жыл бұрын
I found a cooler way to solve the first challenge. I like C and pointers so this is how I went about it: std::vector ChangeList(std::vector listOfNums, bool(*IsItOdd)(int)) { std::vector listOfOdds; for(auto num: listOfNums) if(IsItOdd(num)) listOfOdds.push_back(num); return listOfOdds; } bool IsItOdd(int num) { return (num % 2 != 0); } std::vector oddList = ChangeList(listOfNums, IsItOdd);
@laur43036 жыл бұрын
Awesome tutorial, love the functional programming, I didn't know it was possible in C++ before watching your tutorials. Thank you! Second problem. #include #include #include #include #include void FlipArr(std::function func); int Flip(int high, int low); int main() { srand(time(NULL)); FlipArr(Flip); return 0; } void FlipArr(std::function func) { std::vector FlipArray(100); for (auto i : FlipArray) i = func(1, 0); int heads = 0, tails = 0; for (auto i : FlipArray) if (i) heads++; else tails++; std::cout
@derekbanas6 жыл бұрын
I'm happy you enjoyed it and thank you for sharing your solutions :)
@laur43036 жыл бұрын
Anytime! :D
@alexsindledecker36655 жыл бұрын
Instead of std::function, you could write double(*varName)(double param1, param2)
@damianrivas5 жыл бұрын
But you SHOULD use std::function instead of the old C way of doing things. It's a lot easier, at a glance, to see what std::function is for versus void(*functionName)() If you're going to be a C++ programmer, learn the "modern C++" way of doing things.
@sushiljolly44086 жыл бұрын
Derek sir i want to ask something...that if i want to become specialist in website....then which things i should learn firstly so that i can manage my website.....do i need to know about coding and programming for this purpose??
@derekbanas6 жыл бұрын
Yes learn HTML5, CSS3, JavaScript, PHP and MySQL. I have tutorials on all of them
@sushiljolly44086 жыл бұрын
Derek Banas thnx sir😊😊
@LoganCTanner2 жыл бұрын
@13:50 could just subtract 100 by H/T to reduce total instructions
@davidmelendez31444 жыл бұрын
Good stuff man thaks a lot... Hi from Venezuela
@derekbanas4 жыл бұрын
Thank you :) Hi Venezuela
@diyoptics13873 жыл бұрын
I did not know I can use push_back thinking vector is fixed length, so I had to write more loops to get the size of the new list and loop over again from 0 to size :) good news we have push_back! thanks
@davidpereira53036 жыл бұрын
Derek,thanks for your work. How many videos will this series have?
@derekbanas6 жыл бұрын
Thank you for watching :) I'm not really sure. I still have to cover the STL, data structures, algorithms, GUI development, object oriented design and maybe game development
@davidpereira53036 жыл бұрын
Awesome, I look forward for it ;)
@Conorkc863 жыл бұрын
I did the heads and tails problem a bit different, I used the Generate random vector function to give me 1 or 0, 100 times. Then counted the 0 as heads. #include #include #include #include #include #include #include #include #include bool IsHead(int num) { if (num == 0) { return false; } else { return true; } } std::vector HeadList(std::vector list, std::function func) { std::vector oddList; for (auto i: list) { if (func(i)) { oddList.push_back(i); } } return oddList; } std::vector GenerateRanVec(int numOfNums, int Min, int Max); int main() { std::vector listFlip = GenerateRanVec(100 , 0, 1); std::vector oddList = HeadList(listFlip, IsHead); std::cout
@DS6Prophet6 жыл бұрын
*Thanks,Derek!Your tutorials are always the best for those new to programming!! :D*
@derekbanas6 жыл бұрын
Thank you very much :)
@DS6Prophet6 жыл бұрын
You are welcome!! :)
@emanuelkokovics6 жыл бұрын
I get this error : main.cpp:95:17: error: 'function' is not a member of 'std' If I use include it works but I still get the Configure hints - Unresolved identifier in the code. And it is annoying. And I do not understand how is it working for you without include. I will try to find out more about this error.
@mcmiloy33226 жыл бұрын
Hey Derek, I have to #include to use std::function, why don't you have to?
@iLinked6 жыл бұрын
i dont really have an answer to your question, but i just spazz out every time people dont do using namespace std; at the start of there program, it makes the code alot nicer and makes u able to type stuff much faster. so instead of doing std::function you could just do function
@extazzyyes76726 жыл бұрын
Its considered bad practice to write 'using namespace std' since it pollutes your namespace.
@patrykpekala89484 жыл бұрын
Interesting detail, I found out: Instead of IsItOdd you could also pass a lambda expression to ChangeList 🙂
@JohnDoe-lo6hu2 жыл бұрын
problem 1 : vector is not a list =) is an arrrray - but thank you sir for this great practice and nice video
@Castelino6766 жыл бұрын
IsItOdd you could just have 1 line. return num%2; Or return (num%2!=0);
@derekbanas6 жыл бұрын
Yes I was being verbose
@emanuelclur28115 жыл бұрын
@@derekbanas I'd though exactly the same hahah in these moment was something like """"""advanced"""" functions xd
@tonsantos216 жыл бұрын
Great video, Derek! I am learning a lot! What about a "Learn to build iOS apps" series? I am very thankful for the content that you provide. Keep doing this great job!
@derekbanas6 жыл бұрын
Thank you very much :) I can cover how to make iOS apps using Xamarin, which is what I've been using for the last few years
@thegeeksides6 жыл бұрын
currently studying one using swift (and xcode)... altho im curious how they do it in xamarin. Btw, android development tutorials wud be cool, Derek! Thank you for providing us so many useful informations for free as well. :)
@DivusMeta6 жыл бұрын
Little solution to second problem: ``` std::vector generateSet(int length) { std::vector set(length); srand(time(NULL)); std::generate(set.begin(), set.end(), [](){ return std::rand() % 2; }); return set; } int countOccurrences(std::vector vect, short i) { int counter{0}; std::for_each(vect.begin(), vect.end(), [&counter, i](short j){ counter += (j == i ? 1 : 0); }); return counter; } int main() { std::vector set = generateSet(100); // here I let 1: tails, 0 heads int numOfTails = countOccurrences(set, 1); int numOfHeads = countOccurrences(set, 0); std::cout
@yerngames6 жыл бұрын
Amazing video!
@derekbanas6 жыл бұрын
Thank you :)
@SongSeeker76 жыл бұрын
I came up with this for oddlist with help from your Lambda Functions Tutoarial: Looking forward to arduino electronics :) #include #include #include void ChangeList( // Reference to source list const std::vector& randomIntegerList, // Odd integers returned in here std::vector& oddIntegerList, // Provide a function to perform Odd Number check const std::function isItOdd) { for(auto i: randomIntegerList) if( true == isItOdd(i) ) oddIntegerList.push_back(i); } int main() { // This list will be modified directly by ChangeList() std::vector oddList; ChangeList( {1,2,3,4,5,6,7}, oddList, // Lambda function passed in as the Odd Number checker // Odd numbers have a trailing '1' bit [](short n){ return n & 1; } ); // Print results printf("List of Odds: "); for(auto i: oddList) printf("%d ", i); printf("%c", ' '); return 0; }
@derekbanas6 жыл бұрын
Thank you for sharing :) Arduino is coming soon
@zkfdsldfjsdjfl16 жыл бұрын
Aren’t you suppose to have the functions prototype declared at the top before using them or is it optional
@derekbanas6 жыл бұрын
You don't need a prototype if the function comes before main
@MarcusMathiassen6 жыл бұрын
Mike Nelson Having declarations at the top is for conveniece sake and not needed. Only thing that’s needed is that you declare before you use so that the compiler knows what you’re talking about
@zkfdsldfjsdjfl16 жыл бұрын
thanks
@AfroMidoban6 жыл бұрын
Hello, Is there any possible chance of you covering Unity game engine in the future (Game development in C#) ,Or maybe Unreal Engine for C++ ?
@derekbanas6 жыл бұрын
Here is my 31 part video game tutorial kzbin.info/www/bejne/j5yQhGt9gLN-rq8
@Joseph-gq9nd6 жыл бұрын
1st problem: bool IsItOdd(int num) { return !(num % 2 == 0); } std::vector CopyList(std::vector num_list, std::function func) { std::vector new_vec; for (auto x : num_list) if (func(x)) new_vec.push_back(x); return new_vec; } int main() { std::vector num_list = { 1, 2, 3, 4, 5 }; std::vector odd_list = CopyList(num_list, IsItOdd); for (auto x : odd_list) std::cout
@derekbanas6 жыл бұрын
Thanks for sharing :)
@hamzaliaqat71926 жыл бұрын
I'm making a multiplayer turn based game using Firebase kind of like Tic Tac Toe. I got two problems, first is creating a connection between two players (I've already done it but it's not that good) and security issue. Can you give me any idea about the establishing connection?
@derekbanas6 жыл бұрын
You're looking for a basic client server app. You could make this game easily in App Inventor, but I'm guessing you want to use pure Java. This guy made a client server app that should help lakjeewa.blogspot.co.uk/2014/05/simple-android-client-server-application.html
@qiansun65135 жыл бұрын
For the first, I googled online the got some hints to solve it. However, I couldn't fully understand why it works. Could you explain this line ( list.erase(std::remove_if(list.begin(),list.end(),func),list.end()); ) to me. Std::remove_if will return a iterator and in vector::erase, it's the first position to be erased, why it works here? bool IsIteven(int num){ return (num % 2) == 0; } std::vector ChangeList(std::vector list, std::function func){ list.erase(std::remove_if(list.begin(),list.end(),func),list.end()); return list; } int main() { std::vector listOfNums {1,2,3,4,5}; std::vector oddList = ChangeList(listOfNums, IsIteven); std::cout
@Chastor975 жыл бұрын
10:15 hello, Derek. I have a question. How can you return that vector whilst it is allocated in auto memory?
@nandhannatarajan21275 жыл бұрын
auto means something different in modern C++. auto now is used in place of a typename to tell the compiler to deduce the type of the variable from the value it is assigned.
@timonpasslick6 жыл бұрын
Head and tail counter: #include #include #include #include int main() { std::mt19937 engine{static_cast(std::time(0))}; std::uniform_int_distribution distribution{false, true}; std::int_fast16_t heads{0}; for (std::intfast8_t i{0}; i != 100; ++i) if (distribution(engine)) ++heads; std::cout
@ThatGuyDownInThe4 жыл бұрын
This was the kind of humbling I needed, hahahahahaha
@MrAlbinopapa6 жыл бұрын
I chose to use the STL #include #include #include #include bool IsItOdd( const int num ) { return num % 2 == 1; } std::vector ChangeList( const std::vector& list, std::function func ) { std::vector oddList; std::copy_if( list.begin(), list.end(), std::back_inserter( oddList ), func ); return oddList; } int main() { const std::vector listOfNums = { 1,2,3,4,5 }; const std::vector oddList = ChangeList( listOfNums, IsItOdd ); std::cout
@derekbanas6 жыл бұрын
Thank you for sharing :)
@kintrix0073 жыл бұрын
Any reason why IsItOdd isn't like this? bool IsItOdd(int num) { return num % 2 != 0; }
@particle40056 жыл бұрын
Hello. When I run the second program at 3:42, it gives 19 errors. I use Visual Studio 2017 to run the code. Why do your code work but mine not working while both are the same? Thank you.
@derekbanas6 жыл бұрын
What errors are you getting? C++ is C++ in every IDE, so I'm not sure what could be happening
@kedlucid44543 жыл бұрын
same here
@hamzaliaqat71926 жыл бұрын
I got the solution, sorry for disturbing. The problem was when two players clicks on start game at same time, they both read the request field empty and then writes on the field but one of the field got overwritten. I was just writing the expansion n then i got that I can simply put a rule on that the connection field can only be added or removed, it can't overwritten
@derekbanas6 жыл бұрын
Yes you'll need to block receiving input from one player while the other has their turn
@tomjoad69935 жыл бұрын
3:57 Let's see if a human can understand this, because probably not. Okay, I guess we start with the main function. You define a variable called times2. Why did you use the auto keyword? Local variables are auto, by default. So, in order to get the value of times2 we need the value of MultBy2. But to get that, we have to pass an argument into that function, and where did you do that?
@sohamkar8765 жыл бұрын
Okay, so times2 is actually just a function pointer, something like double (*times2)(double). Auto in c++ does not refer to the storage class auto, but instead allows some sort of soft static typing, so int a = 5; can be replaced by auto a = 5; and the compiler will be able to detect at compiler time that a is in fact an int. Now that times2 has been declared as a function pointer, you can pass args into it just like you would to MultBy2.
@habsengleng64876 жыл бұрын
What is the program do you use?
@derekbanas6 жыл бұрын
NetBeans
@seb_SGH3 жыл бұрын
part 10 end part 13 is all you need to maik a turn baist combet system. i'm maiking it now hahaha
@ETiDeQuenVesSendo4 жыл бұрын
You have the voice of Andy Bernard from the Office
@derekbanas4 жыл бұрын
I think that is funny because I don't hear it. I think he was putting on a Western Pennsylvania accent and that is where I live.
@vaibhavvb6346 жыл бұрын
do you know something about........ HOW TO USE *** gotoxy *** in any c++ ide actually i am coding a program to print a diamond pattern but when i use this gotoxy() in atom ide it is asking to declare the scope......but i dont know how to declare the scope for gotoxy()... please help....
@vaibhavvb6346 жыл бұрын
if you want me to send that program please reply then i will paste it overhere.....please help
@vaibhavvb6346 жыл бұрын
can u name that...library
@vaibhavvb6346 жыл бұрын
thanks for ur reply...i hope i'll find out something about it...... thanks again
@HEADSPACEnTIMING4 жыл бұрын
2 years after your initial posting, thank you
@derekbanas4 жыл бұрын
Happy I could help :)
@kehumileabba14505 жыл бұрын
can you do gui tutorial for visual studio
@derekbanas5 жыл бұрын
I'll see what I can do
@sushiljolly44086 жыл бұрын
Hey i m new here...can anyone tell me that i want to learn programming...so from which vedio i should start...because there are lots of vedios here
@derekbanas6 жыл бұрын
This is my beginners series and please ask questions kzbin.info/www/bejne/pKjNcnuHerd_Zpo
@CA-dg6ou5 жыл бұрын
I love your programming and dedication its AMAZING!!!, sorry for screaming 😎
@derekbanas5 жыл бұрын
Thank you very much 😁
@xiao_sings5 жыл бұрын
#include #include #include #include // needed if you want to pass function(s) to another function... // a function that returns true // if the number is obb! bool is_obb(int number) { while (number > 2) { number -= 2; } if (number
@CanadianMang3 жыл бұрын
3 minutes in I was already lost.
@TheDawnOfTheCreeper6 жыл бұрын
I've always thought of switching from C# to C++ for multiple reasons, but from what I can see C++ has a LOT of (std)s and I don't really want any myself
@maksymiliank51356 жыл бұрын
you can always write one line: "using namespace std;" just below the "includes" and you won't need to use "std::" anywhere else, but i dont think its going to be a good solution if your program uses more namespaces
@johnb13916 жыл бұрын
Namespaces can be defined within a given function to net the same benefit but to still allow multiple namespaces to be used. This circumvents the issue of namespace collisions in the global scope.
@persemake60904 жыл бұрын
Don't worry dude there is always std::remove, which serves as an antibiotic.
@ng4logic5 жыл бұрын
after #include just type using namespace std; and you wont need to type std:: every time.. save you a lot of time and less code..
@NicoScholz905 жыл бұрын
Do you know exactly what you add to your namespace with the "using namespace std;" statement? It's great if you do but many beginner programmers do not :) Thats why many tutorials encourage to put the std:: there manually every time. Also you will work with different namespaces all the time in bigger projects so I might as well get used to the look :)
@ng4logic5 жыл бұрын
@@NicoScholz90 i don't exactly know but you have less code and you don't need to worry about puting std::
@ng4logic5 жыл бұрын
@Peterolen everyone has their own method. Both are correct, so use what you used to.
@hamzaliaqat71926 жыл бұрын
Thank you but actually my I'm making my app for both Web and Android. Here is the demo bingocard.netlify.com I wanted to do random opponent like in 8 Ball Pool. When a player clicks on start game, it first read the request field, if it is empty then it'll write its own id there and listen for it until it get deleted and when it gets delete, it connects itself to the very last created game. And if there is already an id there then it deletes that id and create a game using that as opponent.
@derekbanas6 жыл бұрын
For all networked games you need server side code. I'd learn PHP / MySQL and then scrub the data received before putting it into your database. A web service based around JSON would be an easy way to go.
@Rajjain_3 жыл бұрын
#include #include #include #include using namespace std; int generator(){ return rand()%2; } int counter(function yup, int numbers){ int head=0; while(numbers--){ if(generator()){ head++; } } return head; } int main() { srand(time(nullptr)); auto func=generator; int values=100; auto heads=counter(func,values); cout
Mr. Derek there's something I have always wondered. Why do u produce so many video contents. So u are of those who believe that education should be free or u simply believe there's no need to go to college to learn to be a coder ?
@derekbanas6 жыл бұрын
I believe education should be free, but I also don't believe I could ever do as good a job at educating a student as a dedicated professor. I'm just doing the best job I can with my limited resources. At this point making videos doesn't really make me more money. My income on KZbin is mostly dependent on fluctuations in ad payouts rather then the number of videos I upload. I keep making them because I enjoy making them.
@zulumopuku53706 жыл бұрын
I was trying to have your take on self-teaching process, not on the money you presumably make really.
@derekbanas6 жыл бұрын
Yes I believe some people can be self taught. Some people learn better on their own. I'm an example of that. Classroom learning environments move to slow for me. I think most people though need to be motivated to do most any big thing though. Those people need a classroom, grades and the ultimate goal being a degree.
@jaymalasingh27256 жыл бұрын
Derek Banas hii sir i want to know that how you decide what to do next and you are very frequent in it is there any piece of paper or degien diagrams in front of you which gives you path what to do next
@derekbanas6 жыл бұрын
I have a list of the topics I want to cover in the video and then I largely write the code out of my head. I edit out pauses which makes it seem as if everything goes quicker then it actually does. It normally takes me about 2 times as long to film as the finished video shows.
@eriqtrig6 жыл бұрын
Why dont u just use using namespace std; to avoid u typing std::
@GoodBoyDanny4 жыл бұрын
why am I so dumb.
@derekbanas4 жыл бұрын
If the student fails to understand that is my fault and not yours. Please ask me any questions that you have and I'll do my best to help.
@AryamaanThakur6 жыл бұрын
1st
@derekbanas6 жыл бұрын
That was quick :)
@AryamaanThakur6 жыл бұрын
Derek Banas Thanks! But not quicker than your teaching. You're a good teacher!