Thread: Smart Pointers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    >> moveable m;
    >> m = get_moveable();
    Change that to

    auto m = get_moveable();

    and enable optimizations. The former might work if the compiler is smart enough.
    Also, remove "void" from the empty parameter lists.

    EDIT:
    Code:
    struct moveable
    {
    	moveable()
    	{
    		std::cout << "invoking default constructor\n";
    	}
    
    	moveable(moveable const& rhs) = delete;
    
    	moveable(moveable&& rhs)
    	{
    		std::cout << "invoking move constructor\n";
    	}
    
    	auto operator=(moveable&& rhs) -> moveable&
    	{
    		std::cout << "invoking move assignment operator\n";
    		return *this;
    	}
    };
    
    
    auto get_moveable() -> moveable
    {
    	moveable m;
    	return m;
    }
    
    int main()
    {
    	auto m = get_moveable();
    	return 0;
    }
    Output:
    invoking default constructor
    Last edited by Elysia; 01-13-2017 at 01:15 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Smart Pointers
    By cmajor28 in forum C++ Programming
    Replies: 17
    Last Post: 05-10-2015, 12:01 PM
  2. When to use smart pointers?
    By Neo1 in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2012, 10:53 AM
  3. unsure about auto/smart pointers
    By l2u in forum C++ Programming
    Replies: 16
    Last Post: 07-13-2007, 12:55 PM
  4. weak pointers and use_count smart pointers
    By Mario F. in forum C++ Programming
    Replies: 2
    Last Post: 07-29-2006, 07:54 AM
  5. Use Count smart pointers. Need clarification
    By Mario F. in forum C++ Programming
    Replies: 8
    Last Post: 06-26-2006, 03:07 PM

Tags for this Thread