zoukankan      html  css  js  c++  java
  • EffectiveC++ Item25测试

    test case1:

    #include <iostream>
    #include<vector>
    #include <string>
    #include <boost/foreach.hpp>
    #include <boost/shared_ptr.hpp>
    
    using namespace std;
    
    class Widget
    {
    public:
    	Widget(){}
    	Widget(int aData, const string &aStr):m_Data(aData), m_Str(aStr){}
    	Widget(const Widget& lRhs):m_Data(lRhs.m_Data),m_Str(lRhs.m_Str)
    	{
    	}
    	Widget& operator=(const Widget& lRhs)
    	{
    		m_Data = lRhs.m_Data;
    		m_Str = lRhs.m_Str;
    		return *this;
    	}
    	void swap(Widget & theOtherA)
    	{
    		using  std::swap;
    		Widget lTemp = theOtherA;
    		theOtherA = *this;
    		*this = lTemp;
    	}
    	friend ostream& operator<<(ostream &aCout, const Widget &aWidget);
    private:
    	int m_Data;
    	string m_Str;
    };
    
    ostream& operator<<( ostream &aCout, const Widget &aWidget )
    {
    	aCout << "Data: " << aWidget.m_Data 
    		<< "Str: "<< aWidget.m_Str << endl;
    	return aCout;
    }
    
    namespace  std
    {
    	template <>
    	void  swap <Widget>  (Widget &  a,Widget &b)
    	{
    		a.swap(b);
    	}
    };
    
    int main()
    {
    	Widget lWidget1(1,"a");
    	Widget lWidget2(2,"b");
    	cout << "Orgin is : " << endl 
    		<< "lWidget1 :" << lWidget1 
    		<< "lWidget2: "<< lWidget2;
    	lWidget1.swap(lWidget2);
    	cout << "After swap : " << endl 
    		<< "lWidget1 :" << lWidget1 
    		<< "lWidget2: "<< lWidget2;
    	return 0;
    }
    

      

  • 相关阅读:
    Servlet基础
    JSP数据交互(二)
    Nginx的负载均衡策略及配置
    3.Nginx 配置文件详解
    java--IO总结
    网络协议--FTP协议
    java--apache对象池apche-common-pool2
    java--自定义注解(注解在编译时生效)
    java--自定义注解(注解在运行时生效)
    java--反射
  • 原文地址:https://www.cnblogs.com/xiangshancuizhu/p/2709394.html
Copyright © 2011-2022 走看看