How to return && object from function? [duplicate]
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}
This question already has an answer here:
C++11 rvalues and move semantics confusion (return statement)
6 answers
I have TTempTable
class with move symantics. I wrote
TTempTable&& MyFunction() {
TTempTable tmp = f(...);
...
return std::move(tmp);
}
and got no compiler errors.
Was this correct?
c++ return-value rvalue-reference
marked as duplicate by Ben Voigt
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
May 28 at 0:50
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment
|
This question already has an answer here:
C++11 rvalues and move semantics confusion (return statement)
6 answers
I have TTempTable
class with move symantics. I wrote
TTempTable&& MyFunction() {
TTempTable tmp = f(...);
...
return std::move(tmp);
}
and got no compiler errors.
Was this correct?
c++ return-value rvalue-reference
marked as duplicate by Ben Voigt
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
May 28 at 0:50
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Have a look at this rule in the C++ Core Guidelines
– GPhilo
May 27 at 12:56
add a comment
|
This question already has an answer here:
C++11 rvalues and move semantics confusion (return statement)
6 answers
I have TTempTable
class with move symantics. I wrote
TTempTable&& MyFunction() {
TTempTable tmp = f(...);
...
return std::move(tmp);
}
and got no compiler errors.
Was this correct?
c++ return-value rvalue-reference
This question already has an answer here:
C++11 rvalues and move semantics confusion (return statement)
6 answers
I have TTempTable
class with move symantics. I wrote
TTempTable&& MyFunction() {
TTempTable tmp = f(...);
...
return std::move(tmp);
}
and got no compiler errors.
Was this correct?
This question already has an answer here:
C++11 rvalues and move semantics confusion (return statement)
6 answers
c++ return-value rvalue-reference
c++ return-value rvalue-reference
edited May 27 at 12:58
Lightness Races in Orbit
317k59 gold badges527 silver badges877 bronze badges
317k59 gold badges527 silver badges877 bronze badges
asked May 27 at 12:53
DimsDims
14.4k53 gold badges176 silver badges364 bronze badges
14.4k53 gold badges176 silver badges364 bronze badges
marked as duplicate by Ben Voigt
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
May 28 at 0:50
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Ben Voigt
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
May 28 at 0:50
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Ben Voigt
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
May 28 at 0:50
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Have a look at this rule in the C++ Core Guidelines
– GPhilo
May 27 at 12:56
add a comment
|
1
Have a look at this rule in the C++ Core Guidelines
– GPhilo
May 27 at 12:56
1
1
Have a look at this rule in the C++ Core Guidelines
– GPhilo
May 27 at 12:56
Have a look at this rule in the C++ Core Guidelines
– GPhilo
May 27 at 12:56
add a comment
|
1 Answer
1
active
oldest
votes
No, it is not correct.
You're returning a reference to a local variable. That reference is dangling.
Like any dangling thing, the compiler won't [always] diagnose it for you.
Return by value, and remove the std::move
(it's redundant and inhibits elision).
add a comment
|
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
No, it is not correct.
You're returning a reference to a local variable. That reference is dangling.
Like any dangling thing, the compiler won't [always] diagnose it for you.
Return by value, and remove the std::move
(it's redundant and inhibits elision).
add a comment
|
No, it is not correct.
You're returning a reference to a local variable. That reference is dangling.
Like any dangling thing, the compiler won't [always] diagnose it for you.
Return by value, and remove the std::move
(it's redundant and inhibits elision).
add a comment
|
No, it is not correct.
You're returning a reference to a local variable. That reference is dangling.
Like any dangling thing, the compiler won't [always] diagnose it for you.
Return by value, and remove the std::move
(it's redundant and inhibits elision).
No, it is not correct.
You're returning a reference to a local variable. That reference is dangling.
Like any dangling thing, the compiler won't [always] diagnose it for you.
Return by value, and remove the std::move
(it's redundant and inhibits elision).
answered May 27 at 12:56
Lightness Races in OrbitLightness Races in Orbit
317k59 gold badges527 silver badges877 bronze badges
317k59 gold badges527 silver badges877 bronze badges
add a comment
|
add a comment
|
1
Have a look at this rule in the C++ Core Guidelines
– GPhilo
May 27 at 12:56