﻿<?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++博客-梦想成真（C++版）     -随笔分类-C++</title><link>http://www.cppblog.com/AnnieBy/category/10604.html</link><description>学以致用
while (efforts) {gains++;}</description><language>zh-cn</language><lastBuildDate>Tue, 19 May 2009 09:28:34 GMT</lastBuildDate><pubDate>Tue, 19 May 2009 09:28:34 GMT</pubDate><ttl>60</ttl><item><title>C++中struct和class的区别</title><link>http://www.cppblog.com/AnnieBy/archive/2009/05/19/83395.html</link><dc:creator>Betty</dc:creator><author>Betty</author><pubDate>Tue, 19 May 2009 09:23:00 GMT</pubDate><guid>http://www.cppblog.com/AnnieBy/archive/2009/05/19/83395.html</guid><wfw:comment>http://www.cppblog.com/AnnieBy/comments/83395.html</wfw:comment><comments>http://www.cppblog.com/AnnieBy/archive/2009/05/19/83395.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AnnieBy/comments/commentRss/83395.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AnnieBy/services/trackbacks/83395.html</trackback:ping><description><![CDATA[讨论一下结构(struct)与类(class)的区别，你认为结构(struct)有些什么作用，可以完全用类(class)取代么？？ 
--------------------------------------------------------------- 

首先，讨论这个问题应该仅从语法上讨论，如果讨论不同人之间编程风格上的差异，那这个问题是没有答案的。毕竟不同的人偏好不同。 

从语法上，在C++中（只讨论C++中）。class和struct做类型定义时只有两点区别： 
（一）默认继承权限。如果不明确指定，来自class的继承按照private继承处理，来自struct的继承按照public继承处理； 
（二）成员的默认访问权限。class的成员默认是private权限，struct默认是public权限。 
除了这两点，class和struct基本就是一个东西。语法上没有任何其它区别。 

不能因为学过C就总觉得连C++中struct和class都区别很大，下面列举的说明可能比较无聊，因为struct和class本来就是基本一样的东西：
（1）都可以有成员函数；包括各类构造函数，析构函数，重载的运算符，友元类，友元结构，友元函数，虚函数，纯虚函数，静态函数； 
（2）都可以有一大堆public/private/protected修饰符在里边； 
（3）虽然这种风格不再被提倡，但语法上二者都可以使用大括号的方式初始化：A a = {1, 2, 3};不管A是个struct还是个class，前提是这个类/结构足够简单，比如所有的成员都是public的，所有的成员都是简单类型，没有显式声明的构造函数。 
（4）都可以进行复杂的继承甚至多重继承，一个struct可以继承自一个class，反之亦可；一个struct可以同时继承5个class和5个struct，虽然这样做不太好。 
（5）如果说class的设计需要注意OO的原则和风格，那么没任何理由说设计struct就不需要注意。 
（6）再次说明，以上所有说法都是指在C++语言中，至于在C里的情况，C里是根本没有“class”，而C的struct从根本上也只是个包装数据的语法机制。 

  (7)  不管是定义class还是struct， 大括号后面的分号是必需的，因为在类定义之后可以接一个对象定义列表


<img src ="http://www.cppblog.com/AnnieBy/aggbug/83395.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AnnieBy/" target="_blank">Betty</a> 2009-05-19 17:23 <a href="http://www.cppblog.com/AnnieBy/archive/2009/05/19/83395.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习杂记（一）</title><link>http://www.cppblog.com/AnnieBy/archive/2009/05/19/83390.html</link><dc:creator>Betty</dc:creator><author>Betty</author><pubDate>Tue, 19 May 2009 09:17:00 GMT</pubDate><guid>http://www.cppblog.com/AnnieBy/archive/2009/05/19/83390.html</guid><wfw:comment>http://www.cppblog.com/AnnieBy/comments/83390.html</wfw:comment><comments>http://www.cppblog.com/AnnieBy/archive/2009/05/19/83390.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/AnnieBy/comments/commentRss/83390.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/AnnieBy/services/trackbacks/83390.html</trackback:ping><description><![CDATA[平时学习过程中遇到的一些小问题，简单回顾一下：

1
     C/C++预处理器区分大小写吗?
     答：C系语言都区别,如C,C++,C#,Java等；VB.Net不区分大小写
2
      运行时最好将前面的运行黑色窗体关掉；不然可能会有异常
3
      两个Double类型数据相减比较, double 一般不直接==比较  
4
      Int a ; 
      Sqrt(a);中
     a不能为int类型； 可以用sqrt(double (a))
5
     Do clean you folder before zipping a project. 
     You should remove "Debug" folder , *.ncb and *.suo file.
     So the size will become much smaller

6？
      #include<iostream.h>
     When I run in win32 console it should be Without “.h”just like #include<iostream> I don’t know why some books have this phrase  with .h ,
     What differences are there between the two?
7
     Using namespace std;
     This is essencial ,But we must know that
     in the CLR of VC++ projcet there is a sentence named “using namespace system”,
     They are different
8
      #include <stdafx.h>
     If  it is neglected : 
     The included headfiles such as  #include <iostream>  will be  skipped when look for precompiled header 
9
      Write  2==i instead of i==2put the virable behand of the number 
      int * p;  write null==p instead of p==null     
      It doesn't look strange, indead, in company we have to do like that



10
    The function of srand (垂头剪子布)

     If there is no srand but only rand ,then it will output the same data for N times

   “如果不用srand（），而直接用rand（），每次运行产生的随机数都是一样的。这个你写一段代码就可以知道。
      srand（）起设置随机种子的作用. 用srand((unsigned)time(NULL))可以产生伪随机数列，一般情况都可以满足要求.
     详细情况你查MSDN就知道了，上面也有范例，本来想拷过来，算了，你自己看吧，自己动手要好些。”

     Sometimes it will remind me that it will lead loss of data when execute srand(time (NULL)),
     but sometimes once I close the C command window there is no errors in   fact ,I don’t know why

11
      The use of “_itoa” function

    “_Itoa:”can  Converts an integer to a string.but for safe you’d better use “_itoa_s”

12
     The style of code as a engineer the code should be tide up. E.g.
                                        int main()
                                           {int aCnt = 0...
      It must be as this:
                                       int main()
                                          {

                                            int aCnt = 0...

     You can select all text in the .cpp file and call Edit/Advanced/Format Selection. it will tide up the code.


13
     It's not a good way to declare virables in one line. E.g.

                                    int aCnt = 0,eCnt = 0,iCnt = 0,oCnt = 0,uCnt = 0,

     also 

                                    case 'a':case'A': ++aCnt;break;

     should be 

                                   case 'a':

                                   case 'A':

                                   ++aCnt;

                                   break;



<img src ="http://www.cppblog.com/AnnieBy/aggbug/83390.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/AnnieBy/" target="_blank">Betty</a> 2009-05-19 17:17 <a href="http://www.cppblog.com/AnnieBy/archive/2009/05/19/83390.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>