Thursday, 13 July 2017

Reference to a Pointer

Notes for reading C++ Primer 4/e.
void ptrswap(int *&v1, int *&v2) {
    int *tmp = v2;
    v1 = v2;
    v2 = tmp;
}

int main() {
    int i = 10;
    int j = 20;
    int *pi = &i;
    int *pj = &j;

    cout << *pi << "  " << *pj << endl;
    ptrswap(pi, pj);
    cout << *pi << " " << *pj << endl;

    return 0;
}
Result:
10 20
20 10

Reference

Notes for reading C++ Primer 4/e.

Reference

nonconst reference can only reference to the same nonconst object.
int incr(int val) {
  return ++val;
}

int incrRef(int &val) {
  return ++val;
}

int incrRefConst(const int &val) {
  cout << val << endl;

  return val;
}

int main() {
  short v1 = 0;
  const int v2 = 42;
  double v4 = 3.4;

  int v3 = incr(v1);
  v3 = incrRef(v1);  // X: no matching function for call to 'incrRef'
  v3 = incrRefConst(v1);  // 0

  int v5 = incr(v4);
  v5 = incrRef(v4);  // X: no matching function for call to 'incrRef'
  v5 = incrRefConst(v4);  // 3
  cout << v4 << " " << v5 << endl;  // 3.4 3

  return 0;
}


[note]:

  • nonconst refernce parameter 的彈性較低,不能以 const object 初始化,也不能以字面常數 (ex. 42, 'a', "Hello", 3.14...) 或 rvalue 做為 argument.

Monday, 10 July 2017

Knockin' on Heaven's Door

-Original-

Key: G

|    I    |    V    |    ii    |    ii    |
|    I    |    V    |   IV   |   IV   |



-Gun's N' Roses' Version-
Key: Gb

|    I    |    V    |   IV   |   IV   |

Solo
| - 1 2#2 12 | 2 5 2#2 1 | 1--- | --- 61 |
| 6 5- 43 | 45-- 43 | 4 36-- | -- 34 14 |
| 3- 6 1 23 | 2- 3 3 | 1--- | --- 45 |
| - 43 43 45 | - 43 4 46 | --- 56 | 565 23232 1 | 1--- |


-Solo Cover-

Tuesday, 4 July 2017

Key Signature

Note for reading Key Signature.

Circle of Fifths


Key Signature

  • 0#b: C Dm Em F G Am Bdim
  • 1#: G Am Bm C D Em F#dim
  • 2#: D Em F#m G A Bm C#dim
  • 3#: A Bm C#m D E F#m G#dim
  • 4#: E F#m G#m A B C#m D#dim
  • 5#: B C#m D#m E F# G#m A#dim
  • 6#: F# G#m A#m B C# D#m E#dim
  • 6b: Gb Abm Bbm Cb Db Ebm Fdim
  • 5b: Db Ebm Fm Gb Ab Bbm Cdim
  • 4b: Ab Bbm Cm Db Eb Fm Gdim
  • 3b: Eb Fm Gm Ab Bb Cm Ddim
  • 2b: Bb Cm Dm Eb F Gm Adim
  • 1b: F Gm Am Bb C Dm Edim

Reference: