Thread: A question about 'Return Value'

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    A question about 'Return Value'

    I have the following code just for fun

    Code:
    class Base{
    public:
    	Base(){cout<<"Constructor"<<endl;}
    	Base(const Base &obj){cout<<"Copy Constructor"<<endl;}
    	Base & operator=(const Base& obj){
    		cout<<"Operator="<<endl;
    		return *this;
    	}
    };
    
    Base foo(){
    	Base x;
    	return x;
    }
    
    void main(){
    	Base tmp = foo();
    }
    =================
    Why the outputs are only

    Constructor
    Copy Constructor

    But I think the outputs should be:
    Constructor
    Copy Constructor // from return x
    Copy Constructor // from Base tmp = foo();
    Last edited by meili100; 06-03-2007 at 11:44 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Union Question
    By estarapapax in forum C Programming
    Replies: 0
    Last Post: 10-21-2008, 10:08 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  4. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM