0

I'm trying to understand the flow of a code and I came across this code snippet in the header file

typedef std::auto_ptr<Client> auto_ptr_t;

static Client::auto_ptr_t open(const std::string& uri, const std::string& user, const std::string& pass);

Client& open();

where Client is a class and open is some auto pointer function which authenticates client server link. I don't understand two things

  1. why initialize open() as a auto_ptr and what does it mean?
  2. what would client& open() do?

Can someone explain why has it been initialized this way

Abhay Nayak
  • 1,069
  • 1
  • 11
  • 25
  • 8
    Where did you find the code? `std::auto_ptr` have been deprecated since the C++11 standard, and will be removed in the C++17 standard. You should probably stay away from most code containing `std::auto_ptr`. – Some programmer dude Nov 20 '17 at 07:48
  • 2
    As for your questions, do you know what `std::auto_ptr` is? What did your research tell you about it? And `Client& open();` looks like a normal function declaration. What about that declaration are you wondering about? – Some programmer dude Nov 20 '17 at 07:50
  • 1
    I understand smart pointers and its purpose but using it with a variable is easier understand compared to a function, will it destroy the memory allocated to the function or what? why a pointer function and what would it do. – Abhay Nayak Nov 20 '17 at 08:01
  • 1
    and same with the Client& open, i understand that it means we initialize open as a reference of type class, but what would be the benefit of doing that. This code i'm studying is implementation of Haystack protocol in C++. – Abhay Nayak Nov 20 '17 at 08:05
  • 1
    `open` is a ***function*** that you can call, and if called it will ***return*** a reference to a `Client` object. `open` is *not* a reference to an object. – Some programmer dude Nov 20 '17 at 08:08
  • Same thing with the `static` open function. It's a function that you can call, and it will *return* a `std::auto_ptr` object. – Some programmer dude Nov 20 '17 at 08:09

0 Answers0