lundi 23 décembre 2019

Stream scope in c++11

I call this function

Aws::IOStream& getObjectOutcome(const string bucket_name, const string object_name) {
    Aws::S3::S3Client s3_client;
    Aws::S3::Model::GetObjectRequest request;
    request.SetBucket(bucket_name);
    request.SetKey(object_name);
    auto outcome= s3_client.GetObject(request);
    if (!outcome.IsSuccess()) {
      // Handle Errors
    };
    auto &stream = outcome.GetResult().GetBody();
    return stream;
};

using

Aws::IOStream& stream = getObjectOutcome("bucket","key.txt")

However, the scope of the stream is lost. Why?

Is there any way to use unique_ptr to keep the scope?

Aucun commentaire:

Enregistrer un commentaire