目前分類:c++ (10)

瀏覽方式: 標題列表 簡短摘要

一般call function會需要額外記憶體空間

 

學習程式 發表在 痞客邦 留言(0) 人氣()

1.從繼承用法:

 

學習程式 發表在 痞客邦 留言(0) 人氣()

int &fun(int &a)
{
a += 10;

return a;
}

int main() 
{
int a=10;

fun(a) = 5;   ////方法回傳了a的address
cout << a;////5

return 0;
}


學習程式 發表在 痞客邦 留言(0) 人氣()

1.為了區分 靜態成員和 type的區別

只能用在template裡

學習程式 發表在 痞客邦 留言(0) 人氣()

1.初始化列表:在宣告時就給變數預設值  class():variable(value){};

#include <iostream>

學習程式 發表在 痞客邦 留言(0) 人氣()

 

0.

學習程式 發表在 痞客邦 留言(0) 人氣()

2005/6/29 下午 12:10:50
 
int fun(const int a) 表示不可以修改a

學習程式 發表在 痞客邦 留言(0) 人氣()

from:http://zh.cppreference.com/w/cpp/language/explicit
struct A
{
    A(int) { }      // 转换构造函数
    A(int, int) { } // 转换构造函数 (C++11)
    operator bool() const { return true; }
};
 
struct B
{
    explicit B(int) { }
    explicit B(int, int) { }
    explicit operator bool() const { return true; }
};
 
int main()
{
    A a1 = 1;      // OK :复制初始化选择 A::A(int)
    A a2(2);       // OK :直接初始化选择 A::A(int)
    A a3 {4, 5};   // OK :直接列表初始化选择 A::A(int, int)
    A a4 = {4, 5}; // OK :复制列表初始化选择 A::A(int, int)
    A a5 = (A)1;   // OK :显式转型进行 static_cast
    if (a1) ;      // OK :A::operator bool()
    bool na1 = a1; // OK :复制初始化选择 A::operator bool()
    bool na2 = static_cast<bool>(a1); // OK :static_cast 进行直接初始化
 
//  B b1 = 1;      // 错误:复制初始化不考虑 B::B(int)
    B b2(2);       // OK :直接初始化选择 B::B(int)
    B b3 {4, 5};   // OK :直接列表初始化选择 B::B(int, int)
//  B b4 = {4, 5}; // 错误:复制列表初始化不考虑 B::B(int,int)
    B b5 = (B)1;   // OK :显式转型进行 static_cast
    if (b2) ;      // OK :B::operator bool()
//  bool nb1 = b2; // 错误:复制初始化不考虑 B::operator bool()
    bool nb2 = static_cast<bool>(b2); // OK :static_cast 进行直接初始化
}

學習程式 發表在 痞客邦 留言(0) 人氣()

You can return a structure from a function (or use the = operator) without any problems. It's a well-defined part of the language. The only problem with struct b = a is that you didn't provide a complete type. struct MyObj b = a will work just fine. You can pass structures to functions as well - a structure is exactly the same as any built-in type for purposes of parameter passing, return values, and assignment.

Here's a simple demonstration program that does all three - passes a structure as a parameter, returns a structure from a function, and uses structures in assignment statements:

學習程式 發表在 痞客邦 留言(0) 人氣()

1.javascript 中 陣列傳給method是位址,其他則是複製,所以array在method改過後外面的也會變

var c=[5,4,23];

學習程式 發表在 痞客邦 留言(0) 人氣()