Emplace In C++

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 พ.ย. 2024

ความคิดเห็น • 58

  • @abhishekgawali165
    @abhishekgawali165 4 ปีที่แล้ว +1

    Best ever c++ channel,Hope you reach 100K soon, Best Wishes

    • @CppNuts
      @CppNuts  4 ปีที่แล้ว +1

      Thank you so much 😀

  • @mohammedsuhailbasha4860
    @mohammedsuhailbasha4860 5 ปีที่แล้ว +3

    Very beautiful explaination sir.

    • @CppNuts
      @CppNuts  5 ปีที่แล้ว +1

      Thanks man!

    • @mohammedsuhailbasha4860
      @mohammedsuhailbasha4860 5 ปีที่แล้ว +1

      Always Please upload these kind of video's.If any new concepts come in C++ or if any old concepts you was forgot to take means please take that lecture and upload it because always I have followed your series

    • @CppNuts
      @CppNuts  5 ปีที่แล้ว +1

      Sure man!!

  • @surendrareddy2285
    @surendrareddy2285 6 หลายเดือนก่อน

    Thank you so much for your explanation sir!!!,
    This working fine with "set" , If I am doing similar for " vector" using push_back and emplace_back. both constructor & copy constructor are getting called that to If I use both same time.
    int main()
    {
    vector v;
    v.push_back(A(10));
    v.emplace_back(10); // using push_back & emplace_back at same time will lead calls to constructor and copy constructor for emplace_back
    return 0;

    }
    If I use alone its working as expected like set. why sir ?

  • @ankitthakar2671
    @ankitthakar2671 5 ปีที่แล้ว +2

    In latest version of msvc what I have observed is that if you call push_back also. It internally calls emplace_back. So that objects can be constructed implace only.
    Correct me if i am wrong.

    • @CppNuts
      @CppNuts  5 ปีที่แล้ว

      Not sure about this man!!
      How do you know this is the behavior?

    • @ankitthakar2671
      @ankitthakar2671 5 ปีที่แล้ว

      @@CppNuts
      When I was using vec.push_back()
      I tried to navigate into push_back method through which i come to know that internally it calls emplace only.

    • @behindthescene4406
      @behindthescene4406 4 ปีที่แล้ว

      Ankit bro can u explain me 15 n 16 th line ..I didn't get as I am new to CPP
      Thanks

    • @chaithanyareddy5855
      @chaithanyareddy5855 2 ปีที่แล้ว

      @@behindthescene4406 15 th line is a constructor , but 16 i don't have any idea .. 🤔is it a destructor .. nope !

    • @manishn54
      @manishn54 2 ปีที่แล้ว

      ​@@chaithanyareddy5855 the 16th line is a copy constructor.

  • @vamsikrishna_sampangi
    @vamsikrishna_sampangi 4 ปีที่แล้ว +4

    Any particular reason, why operator function (

    • @MinhTran-wn1ri
      @MinhTran-wn1ri 4 ปีที่แล้ว +5

      A property of a set is that all elements within the set is unique -- they don't compare "equal". Because std::set is templated and can contain anything, including the user-defined class A in this video, you must tell the set how to compare two type A objects. You'd think you'd do this by overloading the == operator but actually, you have to overload the < operator.
      You can define equality in terms of

    • @vasantprabhu
      @vasantprabhu 3 ปีที่แล้ว

      i had to write < inside the class def , and also make it friend ..otherwise it wasnt compiling

  • @Virus-ke8xj
    @Virus-ke8xj 4 ปีที่แล้ว +4

    while defining constructor in line no.15, why did u use x{x},please explain...

  • @jaydeeppawar3696
    @jaydeeppawar3696 3 ปีที่แล้ว

    Great work friend, its really awesome, keep it up!

    • @CppNuts
      @CppNuts  3 ปีที่แล้ว +1

      Thank you, I will

  • @nightmare_9
    @nightmare_9 3 ปีที่แล้ว

    Really Great Explanation !! ❤❤❤

    • @CppNuts
      @CppNuts  3 ปีที่แล้ว

      Glad you liked it!

  • @shraddhaprajapati2589
    @shraddhaprajapati2589 3 ปีที่แล้ว

    sir if possible can u please explain the constructor syntax used. both first and second one plz sir plx

  • @CityDon100
    @CityDon100 4 ปีที่แล้ว

    Sir pls make a video on bool operator . I am little confuse while using this operator.

  • @vvpChannel3112
    @vvpChannel3112 4 ปีที่แล้ว +1

    sir, do we have videos on move semantics , move constructor or RValue Reference ?

    • @CppNuts
      @CppNuts  4 ปีที่แล้ว

      Forgot these topics, will cover sometime later.

    • @behindthescene4406
      @behindthescene4406 4 ปีที่แล้ว

      Bro I didn't understand the comparison function can u plz explain it to me

  • @trojanhorse8278
    @trojanhorse8278 ปีที่แล้ว

    @6:19 can you please shed some light on why inside for loop u wrote those lines? under what topic they come? Is it part of iterators used with stl or something else?

    • @veereshranjan3519
      @veereshranjan3519 3 หลายเดือนก่อน

      It's "range for" operator denoted by :
      This can be used on any containers that has begin and end methods.
      This is usually used instead of conventional for loop where we have int i

    • @veereshranjan3519
      @veereshranjan3519 3 หลายเดือนก่อน

      Also, Here he used to display contents of every object of class A in set

  • @Bottleman1999
    @Bottleman1999 3 ปีที่แล้ว

    wouldnt it also with with Set.insert(2) because you have a constructor that takes 1 int without explicit declaration, so it does implict conversion

  • @srinathsethumadhavan739
    @srinathsethumadhavan739 5 ปีที่แล้ว +1

    what is the role of code in line number 19????
    what is bool return type returning here
    detailed explanation plz

    • @CppNuts
      @CppNuts  5 ปีที่แล้ว +1

      While inserting in SET if our data type is user defined then we need compare function which will be called automatically so that SET data structure can decide which object is smaller and which on is bigger.

  • @sajit1988
    @sajit1988 5 ปีที่แล้ว +2

    Would like to hear "template meta programming" from you

    • @CppNuts
      @CppNuts  5 ปีที่แล้ว +1

      Sure man..

  • @karthickkumar1380
    @karthickkumar1380 3 ปีที่แล้ว

    God You;

    • @CppNuts
      @CppNuts  3 ปีที่แล้ว

      Thanks dude..

  • @piyushkumar-wg8cv
    @piyushkumar-wg8cv 4 ปีที่แล้ว +1

    Can you please explain why copy contructor is called without being called?

    • @CppNuts
      @CppNuts  4 ปีที่แล้ว +1

      You don't see it when u write code, but when compilation happen then so much of new code is injected. And that time explicit call will be there.

  • @anilkrajamoni1484
    @anilkrajamoni1484 4 ปีที่แล้ว

    what is the purpose of the &rhs ans &lhs , im a beginner ,dont mind ,please help me out.

  • @aswindev.t1963
    @aswindev.t1963 5 ปีที่แล้ว +2

    Could you make Datastructure tutorial fast..I was waiting for it

    • @CppNuts
      @CppNuts  5 ปีที่แล้ว +5

      Even i am waiting for that time, my timings are messed-up, too much of office work.
      Now i am able to breath, you can expect it soon.
      Sorry to keep you waiting dude.

  • @KishoreKumar-pf8ku
    @KishoreKumar-pf8ku 3 ปีที่แล้ว

    what is this way of using Constructors called? A(int x=0):x{x}{}; and how do we set multiple members in this way?

  • @ayushsahu736
    @ayushsahu736 2 ปีที่แล้ว

    Amazing

  • @jumbo999614
    @jumbo999614 4 ปีที่แล้ว

    Line 19 I tried to put it inside the class's definition like:
    class
    {...
    bool operator < (const A& rhs)
    {
    return this->x < rhs.x;
    }
    }
    Doesn't work. Only works with operator +=, ++, - -

  • @vinayachandra7498
    @vinayachandra7498 3 ปีที่แล้ว

    What if class has multiple member variable

  • @vvpChannel3112
    @vvpChannel3112 5 ปีที่แล้ว +1

    How this can be used in std::map ?

    • @CppNuts
      @CppNuts  5 ปีที่แล้ว

      It similar, just pass key, value in emplace funtion.

    • @vvpChannel3112
      @vvpChannel3112 5 ปีที่แล้ว +1

      @@CppNuts But we use make_pair func to pass object in insert func ..can you show by one line example?

    • @CppNuts
      @CppNuts  5 ปีที่แล้ว +2

      Map.emplace(key,value);

  • @olask7343
    @olask7343 5 ปีที่แล้ว +1

    Great! 😍

  • @johntrump5656
    @johntrump5656 4 ปีที่แล้ว

    The best ♥️♥️

    • @CppNuts
      @CppNuts  4 ปีที่แล้ว

      Thanks..

  • @programacionpse3520
    @programacionpse3520 2 ปีที่แล้ว

    This's can't help ! SORRY for this comment!

    • @CppNuts
      @CppNuts  2 ปีที่แล้ว

      Sorry