2012年10月14日 星期日

POSD學習筆記(2)-UML與coding

Dependency (uses a)  X-->Y
Ex:X uses Y,X call Y的funtion。

Association (knows a)  X→Y
Ex:X knows Y,X new了Y,且可使用Y的變數及funtion。

Composition (has a)  X◆→Y
Ex:X has a Y,X有Y做為他的變數。

Inheritance (is a)  X△→Y
Ex:Y is a X,Y繼承了X。

Implementation (can do)  X△-->Y
Ex:Y can do X,Y可以做X可以做的事情,可是Y不是X。

2012年10月5日 星期五

C++學習筆記(2)-雙冒號的使用

:: 雙冒號可以使用在...

1.定義某一class內method的實作
    ex1:
    class ex{
      public:
        int testValue;
        int test1(int a);
    };

    int ex::test1(int a){
       return a;
    }

2.也可以用來讀取class內的變數值
    ex2:
    承ex1...
    int ex::test1(int a){
      return a + ::testValue;
    }

C++學習筆記(1)-class與struct的差別

 引用:
   根據C++ standard的描述, class 和 struct 對於 class definition 的差別在於:
   1. 對於 member 的 default access level 不同(std.11)
   2. 對於 base class 的default access level 不同(std.11.2)

整理:
1. class預設權限為private,struct預設權限為public
2. 兩者在C++可以互相繼承
3. C++原本叫做C with Class,可以看出Class為C++的核心理念
4. 兩者幾乎無異,可以只使用其一
5. 若要 class 或 struct 能做 expilcit inialization,該 class 不能有 constructor,不能有 private or protected data member,不能有 base calss,以及不能有 virtual function




expilcit inialization(initializing array):以array的方式做initial
ex:class A{
         int a;
         string b;
         double c;
     }
     
     A test = {1, "a", 1.0};//initialize A 裡面的變數