﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Lua与C++的故事-随笔分类-设计模式</title><link>http://www.cppblog.com/xfpl-at-hotmail-dot-com/category/12156.html</link><description>记录侠客西风的成长</description><language>zh-cn</language><lastBuildDate>Sat, 24 Oct 2009 11:29:50 GMT</lastBuildDate><pubDate>Sat, 24 Oct 2009 11:29:50 GMT</pubDate><ttl>60</ttl><item><title>我的第一个设计模式 单例模式</title><link>http://www.cppblog.com/xfpl-at-hotmail-dot-com/archive/2009/10/24/99365.html</link><dc:creator>侠客西风</dc:creator><author>侠客西风</author><pubDate>Sat, 24 Oct 2009 10:52:00 GMT</pubDate><guid>http://www.cppblog.com/xfpl-at-hotmail-dot-com/archive/2009/10/24/99365.html</guid><wfw:comment>http://www.cppblog.com/xfpl-at-hotmail-dot-com/comments/99365.html</wfw:comment><comments>http://www.cppblog.com/xfpl-at-hotmail-dot-com/archive/2009/10/24/99365.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/xfpl-at-hotmail-dot-com/comments/commentRss/99365.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/xfpl-at-hotmail-dot-com/services/trackbacks/99365.html</trackback:ping><description><![CDATA[<p>样例代码:<br><br>并不完整,没有考虑copy 构造函数和赋值构造函数的情况...仅作演示单例模式使用</p>
<p>class PicData<br>{<br>public:</p>
<p>&nbsp;~PicData()<br>&nbsp;{<br>&nbsp;}</p>
<p>&nbsp;static PicData &amp; getPicData()<br>&nbsp;{<br>&nbsp;&nbsp;static PicData theInstance;<br>&nbsp;&nbsp;return theInstance;<br>&nbsp;}</p>
<p>protected:<br>&nbsp;PicData()<br>&nbsp;{<br>&nbsp;}<br>};</p>
<br>使用:<br>直接在需要用到的地方调用<br>PicData::getPicData();<br>如果需要多次使用,也可以定义一个引用来简化操作.<br>单例模式据说是设计模式中最简单的一种,我现在主要用它来代替全局变量,保证有特殊要求的类在程序运行期间的唯一性.<br><br>可以写一个模板类,然后从模板类派生自己需要使用的单例类...
<img src ="http://www.cppblog.com/xfpl-at-hotmail-dot-com/aggbug/99365.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/xfpl-at-hotmail-dot-com/" target="_blank">侠客西风</a> 2009-10-24 18:52 <a href="http://www.cppblog.com/xfpl-at-hotmail-dot-com/archive/2009/10/24/99365.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>