Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5838379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:27:42+00:00 2026-05-22T11:27:42+00:00

I am new to C++. Please consider the following code: class foo { int

  • 0

I am new to C++. Please consider the following code:

class foo 
{ 
 int f; 

 public: 
   foo(int f1=0) : f(f1) { 
   cout<<"In conversion ctor\n"; 
 } 

foo(const foo & rhs) : f(rhs.f) 
{ 
    cout<<" In copy ctor\n"; 
} 

 foo& operator=(const foo & that) 
{ 
    f=that.f; 
    cout<<"In = optor\n"; 
    return *this; 
} 

}; 

 foo rbv() 
  { 
    foo obj(9); 
    return obj;                        //named return by value [def. 1] 
  } 

   foo caller() 
   { 
      return rbv();              // return by value [def. 2] 
   } 

int main(void) 
{ 
   foo box=caller(); 
   return 0; 
 }
  1. Are the definitions for RBV and NRBV correct as indicated in the
    comments?
  2. Is it mandatory to have an accessible copy ctor defined though it
    is not called during RVO?
  3. Without RVO, in the code blocks

       foo rbv() 
        { 
         foo obj(9); 
         return obj; 
        } 
    
        foo ret= rbv();
    

Are the following steps correct in creation of ‘ret’

(1) a temporary ( say obj_temp) is created using copy ctor from obj,
stack object ‘obj’ destroyed,

(2) ret is copy constructed from obj_temp, obj_temp destroyed later;

which implies there are three objects, ‘obj’ , ‘obj_temp’ and ‘ret’ and two copy ctors involved.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:27:42+00:00Added an answer on May 22, 2026 at 11:27 am
    1. Looks right to me.
    2. You have to have an accessible copy constructor defined if you are going to copy objects. Even if the copy can be optimized away.
    3. That sounds right to me, though the precise ordering might be implementation defined. You would have to
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: def create_class(class_name, superclass, &block) klass = Class.new superclass, &block Object.const_set
Please pardon me for a n00bish question. Please consider the following code: public class
Please consider the following piece of code: int main() { typedef boost::ptr_vector<int> ptr_vector; ptr_vector
Please consider the following code: class Student { } enum StudentType { } static
Please consider the following code: <?php class MyException extends Exception {} function global_exception_handler($exception) {
Please consider the following: class CMyClass { public: CMyClass() { printf( "Constructor\n" ); }
Please consider the following class: public class Level : IDisposable { public Level() {
Please consider the following code and the explanation from this Mozilla tutorial Using web
Please consider the following fork() / SIGCHLD pseudo-code. // main program excerpt for (;;)
consider the following example: public IEnumerable<String> Test () { IEnumerable<String> lexicalStrings = new List<String>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.