Advertisement

poker game

Started by November 01, 2024 12:29 AM
158 comments, last by pbivens67 4 hours, 27 minutes ago

pbivens67 said:

I am not very good with pointers so this line of code perplexes me.

Sigh.

Nothing special going on here. The function argument should have been written as HandInfo &hand because there was not any desire to set hand to nullptr. As a pointer or as a reference, they basically work the same avoiding a copy. That's my bad. Just consider hand as an alias of player_hand or dealer_hand depending on which address was passed in.

Dev careful. Pixel on board.

You are automagically dereferencing the pointer when you use the arrow operator. These two cout lines are equivalent:

#include <iostream>
using namespace std;

class A
{
public:
    int m = 12345;
};

int main(void) 
{
    A a;
    A *b = &a; // Here & is the address-of operator

    cout << b->m << endl; // Automatically dereference
    cout << (*b).m << endl; // Manually dereference

    return 0;
}

Also, you should go through the entirety of https://www.w3schools.com/cpp/default.asp before you continue on your C++ journey. You need to read a reference.

Advertisement

@taby I am reading a book on c++ , I am working on the sorting and searching chapter and am doing the exercises in the back of the chapter

Nice. 🙂

I am doing my best to learn c++

Do you understand that a pointer is just another kind of variable, and that it stores a memory address? It literally points to the memory address.

We know that an invalid pointer stores the address 0, because this base address is guaranteed to be already taken up by the first byte of the operating system, making it unavailable for general use.

Advertisement

so in my latest code how do I initialize the Handinfo *hand=0; statement.

Which code is your latest code? Do you have a Github repository?

it is on page15 middle of the posts

Advertisement