Reference Data Member In C++

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

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

  • @cid007007
    @cid007007 4 года назад +2

    Similarly we can have pointer as data member :
    #include
    using namespace std;
    class Base
    {
    int *x;
    public:
    Base(int &a): x{&a} {}
    void getX(){ cout

  • @abhijithnair9175
    @abhijithnair9175 4 года назад +1

    In the last example shown, when a int pointer is passed, the data member should have been a int * & Integer Pointer refernce right?
    Correct me if I m wrong

    • @CppNuts
      @CppNuts  4 года назад

      If integer pointer is passed you can receive it in integer pointer.

  • @yogendragangwar9795
    @yogendragangwar9795 4 года назад +1

    Hi there i have one question that, why we can not be a reference variable as NULL, Please reply if you see the comment

    • @suryabhansingh7553
      @suryabhansingh7553 4 года назад

      Reference do not store address of value it is another name of any variable

    • @omsrinivaskaradava9275
      @omsrinivaskaradava9275 3 года назад

      @@suryabhansingh7553 So sir then did reference var will have any address or location or it is just a another name of original var. Bcz when we are declaring any reference what will be size of allocation for it

  • @Kart4Lake
    @Kart4Lake 6 лет назад +1

    could you tell me what editor u used, seem good, can compile too . ty

    • @CppNuts
      @CppNuts  6 лет назад

      I am using Sublime Text Editor and Migw compiler.

  • @ohmnamo7056
    @ohmnamo7056 4 года назад +1

    thanks for the video bro....does the reference of one instance of class can change the data of another instance of class .Or reference is done within the same instance of class?

    • @CppNuts
      @CppNuts  4 года назад +1

      It can change.

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

    difference between int &a and int& a ??

  • @im_raccoon
    @im_raccoon 4 года назад

    your explanation is seriously mindblowing and i am really enjoying this c++ series,but man i hv a request for you, that is a lots of ads are comming in between a single vedio like in every next two minutes.pls do smthing abt it.

  • @aftabalam5521
    @aftabalam5521 6 лет назад +1

    Nice explanation. Your voice is like ritik roshan.

    • @CppNuts
      @CppNuts  6 лет назад

      Hi Aftab glad you liked the video, and that compliment is so big for me thanks man (a fan of Hrithik Roshan).

    • @aftabalam5521
      @aftabalam5521 6 лет назад +1

      In the first example, what if we pass like this?
      int &x;
      Base(int a) : x(a) {}
      Base obj(10);

    • @CppNuts
      @CppNuts  6 лет назад

      10 is R-value so it should throw error. because you can get the reference of L value not the R value.
      and if you're not sure what is this I may be giving the video but for now you should go and search what is L value and R value in C plus plus.

    • @aftabalam5521
      @aftabalam5521 6 лет назад

      CppNuts thanks, but I am passing 10 to int a and want that x refer to a

    • @aftabalam5521
      @aftabalam5521 6 лет назад

      CppNuts definitely I will look into L and R value, its always a confusion for me. Thanks a lot

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

    I use by value and worked with const;

  • @aniketahir101
    @aniketahir101 4 года назад

    Make a seperate video about rvalue reference operator ( && ). Thank u.