Pointer or reference?

Hi all,
in an existing code I found this notation:

PINK* boon = static_cast<PINK*>(car.get());

where car is a shared pointer to a container and PINK a specific class. Now I know I can access the attributes of boon something like:

boon->name

What I wonder is: what is now boon? I imagine is a pointer. If so, can I pass boon->name to a function that accepts a float variable? What type is boon->name ?

Sorry but I am still confused with pointers/references and so on.

Thanks a lot for any comment,

Chiara
Last edited on
The type of boon->name is defined with class PINK because boon it being treated as an object of type PINK pointer.
1
2
3
4
5
6
7
8
9
10
11
#include <string>

class PINK
{
public:
    std::string name;
};

PINK* boon = new PINK;

boon->name; // In this example boon->name is of type std::string 
Hi Galik,
OK, so if in PINK class name is of double type, so it is boon->name. Can I pass it to a function which only accepts double variables? Or should I make a copy before going on, like

double Name = boon->name;

cheers, Chiara

You can pass it directly to a function.
1
2
3
4
5
6
7
8
9
10
11
12

void func(double d);

int main()
{
    PINK* boon = new PINK;

    func(boon->name);

    return 0;
}
Topic archived. No new replies allowed.