What are C++ FUNCTION TEMPLATES? 🍪

Поделиться
HTML-код
  • Опубликовано: 20 янв 2025

Комментарии • 31

  • @BroCodez
    @BroCodez  2 года назад +12

    #include
    template
    T max(T x, T y){
    return (x > y) ? x : y;
    }
    int main()
    {
    std::cout

  • @ChrisVideosGreek
    @ChrisVideosGreek 2 года назад +9

    l just learned about this channel and it's AMAZING! Really nice job, big like for the explaination and for that huge series!

  • @maxenceveilleux
    @maxenceveilleux 8 месяцев назад +10

    If anyone's max function doesn't return values the same way it does in the video, it may be because you've typed "using namespace std;" at the top of your file. I recommend you to remove it because there is a function that is called max() in that std library and C++ thinks it needs to choose this function rather than yours.

  • @mandarparkhi3708
    @mandarparkhi3708 Месяц назад +1

    It was useful. nice and simple. Thanks for sharing.

  • @manipurihunabopa
    @manipurihunabopa Год назад

    This video has reduced ambiguity about fiction template which was increased by other video tutorials .
    However, class templates remains a mystery to me. I just can't comprehend it thoroughly. Can you bro make an extensive video tutorial on Class templates? Are they really useful?

  • @protomous
    @protomous Год назад +4

    When attempting
    template
    auto max(T x, U y){}
    I get an error saying ‘auto’ not allowed in function return type, even though I should have the most updated C++ extension on VS Code. Any ideas?

    • @ThisL1ght
      @ThisL1ght Год назад

      Try returning this: return (x > y) ? x : y;

  • @FrederikWollert
    @FrederikWollert 9 месяцев назад

    Awesome video again. So there is no reason at all to use an overloaded function anymore?

  • @sihleebuthelezi9231
    @sihleebuthelezi9231 2 года назад +2

    Bro when I add namespace std, the templates don't work, do you know why?

    • @ruthkuhne8346
      @ruthkuhne8346 Год назад +2

      I'm not sure if you had fixed it, but you can write " cout

  • @feedertayfa8745
    @feedertayfa8745 День назад

    So is this java's generic equivalent in c++? I know it is other way but in simple saying.

  • @jessechen2132
    @jessechen2132 2 года назад

    Is the template only used above the main function?

  • @gitanshu-u7g
    @gitanshu-u7g Месяц назад +2

    why was i kept away from this video

  • @HunaBopa
    @HunaBopa Год назад +2

    my assignment:
    // -----------------------------------------project name: multiple function template
    // write a function once, then it's compatible with different data types = that's function template. With auto keyword the function return type is automatically detected or deduced by the compiler
    #include
    template
    auto max(T x, U y)
    {
    return (x > y) ? x : y;
    }
    int main()
    {
    std::cout

  • @AaronPereira-k3r
    @AaronPereira-k3r 3 месяца назад +2

    You could use auto instead

  • @nitrobeast6629
    @nitrobeast6629 5 месяцев назад

    copied your code with the auto keyword word for word and got an error?

  • @Anonymous-st1vk
    @Anonymous-st1vk 4 месяца назад +3

    Why not always use auto?

    • @RandomCommentator15
      @RandomCommentator15 3 месяца назад +3

      Not optimal for big functions. While we use auto, the function becomes dynamic. Also, it comes at the cost of code readability and makes it harder to debug. :)

  • @nhantran-rw1ui
    @nhantran-rw1ui Год назад

    this is very useful

  • @TheG-studios
    @TheG-studios Месяц назад +1

  • @yahyaarfaoui8526
    @yahyaarfaoui8526 Год назад +1

    why don't we just turn them all auto
    #include
    auto max(auto x , auto y){
    return (x>y) ? x : y ;
    }
    int main () {
    std::cout

    • @anvrag
      @anvrag Год назад +2

      The auto keyword is not allowed as a parameter type in C++ function declarations.

  • @PCgamers69420
    @PCgamers69420 3 месяца назад

    template

  • @defeatSpace
    @defeatSpace 3 месяца назад

    🤯

  • @dazai826
    @dazai826 7 месяцев назад +3

    #include
    #include // For sqrt() function
    template
    float distance(T v1, U v2, V v3){
    return sqrt(v1 * v1 + v2 * v2 + v3 * v3);
    }
    int main(void){
    // Example Usage
    std::cout

  • @PaulKrueger-r7j
    @PaulKrueger-r7j 6 месяцев назад +1

    #include
    template
    auto min(T x, U y){
    return (x < y) ? x : y;
    }
    int main(){
    std:cout

  • @Dazza_Doo
    @Dazza_Doo 2 года назад

    ahh Template == Generics
    auto is like var

  • @jonia4912
    @jonia4912 8 месяцев назад

    #include
    template
    auto min(T x, U y){
    return (x < y) ? x : y;
    }
    int main()
    {
    std::cout

  • @danaildoganov
    @danaildoganov 9 месяцев назад

    #include
    template
    auto min(T x, U y){
    return (x < y) ? x : y;
    }
    int main () {
    std::cout

  • @ThisL1ght
    @ThisL1ght Год назад

    #include
    template
    auto max(T x, U y){
    return (x > y) ? x : y;
    }
    int main()
    {
    std::cout

  • @heavyymetal
    @heavyymetal 2 года назад

    auto min(T x, U y){
    return(x < y) ? x : y;
    }