C++ 構(gòu)造函數(shù)和析構(gòu)函數(shù)示例詳解
構(gòu)造函數(shù)(Constructor)
什么是構(gòu)造函數(shù)?
構(gòu)造函數(shù)是一種特殊的成員函數(shù),在創(chuàng)建類(lèi)對(duì)象時(shí)自動(dòng)調(diào)用,用于初始化對(duì)象的數(shù)據(jù)成員。
構(gòu)造函數(shù)的特點(diǎn)
- 與類(lèi)同名
- 沒(méi)有返回類(lèi)型
- 可以重載
- 自動(dòng)調(diào)用
構(gòu)造函數(shù)的類(lèi)型
1. 默認(rèn)構(gòu)造函數(shù)
class MyClass {
private:
int value;
std::string name;
public:
// 默認(rèn)構(gòu)造函數(shù)(無(wú)參數(shù))
MyClass() {
value = 0;
name = "Unknown";
std::cout << "Default constructor called" << std::endl;
}
};
// 使用
MyClass obj; // 調(diào)用默認(rèn)構(gòu)造函數(shù)2. 參數(shù)化構(gòu)造函數(shù)
class MyClass {
private:
int value;
std::string name;
public:
// 參數(shù)化構(gòu)造函數(shù)
MyClass(int val, const std::string& n) {
value = val;
name = n;
std::cout << "Parameterized constructor called" << std::endl;
}
};
// 使用
MyClass obj1(42, "Hello");
MyClass obj2 = MyClass(100, "World");3. 拷貝構(gòu)造函數(shù)
class MyClass {
private:
int value;
std::string name;
public:
// 拷貝構(gòu)造函數(shù)
MyClass(const MyClass& other) {
value = other.value;
name = other.name;
std::cout << "Copy constructor called" << std::endl;
}
};
// 使用
MyClass obj1(42, "Original");
MyClass obj2 = obj1; // 調(diào)用拷貝構(gòu)造函數(shù)
MyClass obj3(obj1); // 調(diào)用拷貝構(gòu)造函數(shù)4. 移動(dòng)構(gòu)造函數(shù)(C++11)
class MyClass {
private:
int* data;
size_t size;
public:
// 移動(dòng)構(gòu)造函數(shù)
MyClass(MyClass&& other) noexcept {
// "竊取"資源
data = other.data;
size = other.size;
// 置空原對(duì)象
other.data = nullptr;
other.size = 0;
std::cout << "Move constructor called" << std::endl;
}
};初始化列表
class Student {
private:
std::string name;
int age;
const int id; // 常量成員
int& ref; // 引用成員
public:
// 使用初始化列表(推薦)
Student(const std::string& n, int a, int studentId, int& r)
: name(n), age(a), id(studentId), ref(r) {
std::cout << "Student constructor called" << std::endl;
}
// 錯(cuò)誤示例:不能在構(gòu)造函數(shù)體內(nèi)初始化常量和引用
// Student(const std::string& n, int a, int studentId, int& r) {
// name = n;
// age = a;
// id = studentId; // 錯(cuò)誤!常量必須在初始化列表中初始化
// ref = r; // 錯(cuò)誤!引用必須在初始化列表中初始化
// }
};析構(gòu)函數(shù)(Destructor)
什么是析構(gòu)函數(shù)?
析構(gòu)函數(shù)是一種特殊的成員函數(shù),在對(duì)象銷(xiāo)毀時(shí)自動(dòng)調(diào)用,用于清理資源。
析構(gòu)函數(shù)的特點(diǎn)
- 類(lèi)名前加
~ - 沒(méi)有參數(shù)
- 沒(méi)有返回類(lèi)型
- 不能重載
- 自動(dòng)調(diào)用
析構(gòu)函數(shù)示例
class MyClass {
private:
int* data;
size_t size;
public:
// 構(gòu)造函數(shù)
MyClass(size_t s) : size(s) {
data = new int[size]; // 動(dòng)態(tài)分配內(nèi)存
std::cout << "Constructor: allocated " << size << " integers" << std::endl;
}
// 析構(gòu)函數(shù)
~MyClass() {
delete[] data; // 釋放內(nèi)存
std::cout << "Destructor: freed " << size << " integers" << std::endl;
}
};
// 使用
void test() {
MyClass obj(100); // 構(gòu)造函數(shù)調(diào)用
// ... 使用 obj
} // obj 離開(kāi)作用域,析構(gòu)函數(shù)自動(dòng)調(diào)用完整示例
資源管理類(lèi)示例
#include <iostream>
#include <cstring>
class String {
private:
char* data;
size_t length;
public:
// 默認(rèn)構(gòu)造函數(shù)
String() : data(nullptr), length(0) {
std::cout << "Default constructor" << std::endl;
}
// 參數(shù)化構(gòu)造函數(shù)
String(const char* str) {
length = std::strlen(str);
data = new char[length + 1];
std::strcpy(data, str);
std::cout << "Parameterized constructor: " << data << std::endl;
}
// 拷貝構(gòu)造函數(shù)
String(const String& other) {
length = other.length;
data = new char[length + 1];
std::strcpy(data, other.data);
std::cout << "Copy constructor: " << data << std::endl;
}
// 移動(dòng)構(gòu)造函數(shù)(C++11)
String(String&& other) noexcept {
// 竊取資源
data = other.data;
length = other.length;
// 置空原對(duì)象
other.data = nullptr;
other.length = 0;
std::cout << "Move constructor" << std::endl;
}
// 拷貝賦值運(yùn)算符
String& operator=(const String& other) {
if (this != &other) { // 防止自賦值
delete[] data; // 釋放原有資源
length = other.length;
data = new char[length + 1];
std::strcpy(data, other.data);
}
std::cout << "Copy assignment: " << data << std::endl;
return *this;
}
// 移動(dòng)賦值運(yùn)算符(C++11)
String& operator=(String&& other) noexcept {
if (this != &other) {
delete[] data; // 釋放原有資源
// 竊取資源
data = other.data;
length = other.length;
// 置空原對(duì)象
other.data = nullptr;
other.length = 0;
}
std::cout << "Move assignment" << std::endl;
return *this;
}
// 析構(gòu)函數(shù)
~String() {
delete[] data;
std::cout << "Destructor" << std::endl;
}
// 其他成員函數(shù)
const char* c_str() const { return data ? data : ""; }
size_t size() const { return length; }
};
// 使用示例
int main() {
std::cout << "=== 創(chuàng)建對(duì)象 ===" << std::endl;
String s1; // 默認(rèn)構(gòu)造函數(shù)
String s2 = "Hello"; // 參數(shù)化構(gòu)造函數(shù)
String s3 = s2; // 拷貝構(gòu)造函數(shù)
std::cout << "\n=== 賦值操作 ===" << std::endl;
s1 = s3; // 拷貝賦值
s1 = String("World"); // 移動(dòng)賦值
std::cout << "\n=== 函數(shù)調(diào)用 ===" << std::endl;
{
String temp = "Temporary"; // 參數(shù)化構(gòu)造函數(shù)
} // temp 離開(kāi)作用域,調(diào)用析構(gòu)函數(shù)
std::cout << "\n=== 程序結(jié)束 ===" << std::endl;
return 0;
} // s1, s2, s3 離開(kāi)作用域,調(diào)用析構(gòu)函數(shù)輸出結(jié)果
=== 創(chuàng)建對(duì)象 === Default constructor Parameterized constructor: Hello Copy constructor: Hello === 賦值操作 === Copy assignment: Hello Parameterized constructor: World Move assignment Destructor === 函數(shù)調(diào)用 === Parameterized constructor: Temporary Destructor === 程序結(jié)束 === Destructor Destructor Destructor
特殊成員函數(shù)規(guī)則
Rule of Three/Five/Zero
Rule of Three(C++98/03)
如果一個(gè)類(lèi)需要以下之一,通常需要全部三個(gè):
- 析構(gòu)函數(shù)
- 拷貝構(gòu)造函數(shù)
- 拷貝賦值運(yùn)算符
Rule of Five(C++11及以后)
如果類(lèi)管理資源,應(yīng)該考慮定義全部五個(gè)特殊成員函數(shù):
- 析構(gòu)函數(shù)
- 拷貝構(gòu)造函數(shù)
- 拷貝賦值運(yùn)算符
- 移動(dòng)構(gòu)造函數(shù)
- 移動(dòng)賦值運(yùn)算符
Rule of Zero
理想情況下,類(lèi)不應(yīng)該自己管理資源,而是使用智能指針等RAII類(lèi),這樣編譯器生成的默認(rèn)函數(shù)就足夠了。
// Rule of Zero 示例
class GoodClass {
private:
std::unique_ptr<int[]> data; // 使用智能指針管理資源
std::string name; // 使用標(biāo)準(zhǔn)庫(kù)類(lèi)
public:
// 不需要定義析構(gòu)函數(shù)、拷貝/移動(dòng)構(gòu)造函數(shù)、拷貝/移動(dòng)賦值運(yùn)算符
// 編譯器生成的默認(rèn)函數(shù)就足夠好
GoodClass(const std::string& n) : name(n) {}
};虛析構(gòu)函數(shù)
class Base {
public:
Base() { std::cout << "Base constructor" << std::endl; }
virtual ~Base() { std::cout << "Base destructor" << std::endl; } // 虛析構(gòu)函數(shù)
};
class Derived : public Base {
public:
Derived() { std::cout << "Derived constructor" << std::endl; }
~Derived() override { std::cout << "Derived destructor" << std::endl; }
};
// 使用
Base* ptr = new Derived();
delete ptr; // 正確調(diào)用 Derived 的析構(gòu)函數(shù),因?yàn)橛刑撐鰳?gòu)函數(shù)總結(jié)
- 構(gòu)造函數(shù):對(duì)象創(chuàng)建時(shí)調(diào)用,用于初始化
- 析構(gòu)函數(shù):對(duì)象銷(xiāo)毀時(shí)調(diào)用,用于清理資源
- 重要規(guī)則:
- 使用初始化列表初始化成員
- 管理資源的類(lèi)需要遵循 Rule of Five
- 基類(lèi)應(yīng)該使用虛析構(gòu)函數(shù)
- 優(yōu)先使用 Rule of Zero
構(gòu)造函數(shù)和析構(gòu)函數(shù)是C++中實(shí)現(xiàn)RAII(資源獲取即初始化)模式的基礎(chǔ),對(duì)于資源管理和異常安全至關(guān)重要。
c++中的構(gòu)造函數(shù),如果類(lèi)比python語(yǔ)言的話,在python中相當(dāng)于什么?
C++ 構(gòu)造函數(shù)與 Python 的類(lèi)比
基本對(duì)應(yīng)關(guān)系
| C++ 概念 | Python 對(duì)應(yīng) | 說(shuō)明 |
|---|---|---|
| 構(gòu)造函數(shù) | __init__ 方法 | 對(duì)象初始化 |
| 析構(gòu)函數(shù) | __del__ 方法 | 對(duì)象清理 |
| 默認(rèn)構(gòu)造函數(shù) | 無(wú)參數(shù)的 __init__ | 創(chuàng)建默認(rèn)對(duì)象 |
| 拷貝構(gòu)造函數(shù) | __init__ + 手動(dòng)拷貝 | 對(duì)象拷貝 |
| 移動(dòng)構(gòu)造函數(shù) | 無(wú)直接對(duì)應(yīng) | Python 使用引用計(jì)數(shù) |
詳細(xì)對(duì)比
1. 基本構(gòu)造函數(shù) ↔__init__方法
C++:
class Person {
private:
std::string name;
int age;
public:
// 構(gòu)造函數(shù)
Person(const std::string& n, int a) : name(n), age(a) {
std::cout << "Person created: " << name << std::endl;
}
};
// 使用
Person p("Alice", 25);Python:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
print(f"Person created: {self.name}")
# 使用
p = Person("Alice", 25)2. 默認(rèn)構(gòu)造函數(shù) ↔ 無(wú)參數(shù)__init__
C++:
class MyClass {
public:
MyClass() {
std::cout << "Default constructor" << std::endl;
}
};
MyClass obj; // 調(diào)用默認(rèn)構(gòu)造函數(shù)Python:
class MyClass:
def __init__(self):
print("Default constructor")
obj = MyClass() # 調(diào)用 __init__3. 析構(gòu)函數(shù) ↔__del__方法
C++:
class FileHandler {
private:
FILE* file;
public:
FileHandler(const char* filename) {
file = fopen(filename, "r");
std::cout << "File opened" << std::endl;
}
~FileHandler() {
if (file) {
fclose(file);
std::cout << "File closed" << std::endl;
}
}
};
// 自動(dòng)調(diào)用析構(gòu)函數(shù)
{
FileHandler fh("test.txt");
// 使用文件
} // 離開(kāi)作用域,自動(dòng)調(diào)用析構(gòu)函數(shù)Python:
class FileHandler:
def __init__(self, filename):
self.file = open(filename, 'r')
print("File opened")
def __del__(self):
if self.file:
self.file.close()
print("File closed")
# 使用(注意:Python的__del__調(diào)用時(shí)機(jī)不確定)
fh = FileHandler("test.txt")
# 當(dāng)對(duì)象被垃圾回收時(shí)調(diào)用 __del__4. 拷貝行為對(duì)比
C++ 拷貝構(gòu)造函數(shù):
class Vector {
private:
int* data;
size_t size;
public:
Vector(size_t s) : size(s) {
data = new int[size];
}
// 拷貝構(gòu)造函數(shù)
Vector(const Vector& other) : size(other.size) {
data = new int[size];
std::copy(other.data, other.data + size, data);
std::cout << "Copy constructor called" << std::endl;
}
~Vector() {
delete[] data;
}
};
Vector v1(10);
Vector v2 = v1; // 調(diào)用拷貝構(gòu)造函數(shù)Python 的拷貝行為:
class Vector:
def __init__(self, size):
self.size = size
self.data = [0] * size
# Python 沒(méi)有直接的拷貝構(gòu)造函數(shù)
# 需要手動(dòng)實(shí)現(xiàn)或使用 copy 模塊
v1 = Vector(10)
v2 = v1 # 這只是引用賦值,兩個(gè)變量指向同一個(gè)對(duì)象
v3 = Vector(v1.size) # 手動(dòng)創(chuàng)建新對(duì)象
v3.data = v1.data[:] # 手動(dòng)拷貝數(shù)據(jù)
# 或者使用 copy 模塊
import copy
v4 = copy.deepcopy(v1)重要差異
1. 內(nèi)存管理方式不同
C++ - 手動(dòng)管理,確定性析構(gòu):
{
Person p("John", 30); // 構(gòu)造函數(shù)調(diào)用
// 使用 p
} // p 離開(kāi)作用域,析構(gòu)函數(shù)立即調(diào)用
Python - 自動(dòng)垃圾回收,非確定性析構(gòu):
def test():
p = Person("John", 30) # __init__ 調(diào)用
# 使用 p
# __del__ 可能在函數(shù)結(jié)束后調(diào)用,也可能不立即調(diào)用2. 拷貝語(yǔ)義不同
C++ - 值語(yǔ)義,默認(rèn)深拷貝:
Vector v1(10); Vector v2 = v1; // 深拷貝,兩個(gè)獨(dú)立對(duì)象
Python - 引用語(yǔ)義,默認(rèn)淺拷貝:
v1 = Vector(10) v2 = v1 # 引用拷貝,兩個(gè)變量指向同一個(gè)對(duì)象
3. 構(gòu)造方式不同
C++ - 多種構(gòu)造方式:
Person p1; // 默認(rèn)構(gòu)造
Person p2("Alice", 25); // 直接構(gòu)造
Person p3 = p2; // 拷貝構(gòu)造
Person p4 = Person("Bob", 30); // 臨時(shí)對(duì)象 + 移動(dòng)構(gòu)造
Python - 統(tǒng)一使用 __init__:
p1 = Person() # 需要定義 __init__(self)
p2 = Person("Alice", 25)
p3 = p2 # 引用賦值,不是拷貝
p4 = Person(p2.name, p2.age) # 手動(dòng)創(chuàng)建新對(duì)象
Python 中模擬 C++ 構(gòu)造函數(shù)特性
模擬重載構(gòu)造函數(shù)
Python 使用默認(rèn)參數(shù)和類(lèi)方法模擬:
class Date:
def __init__(self, day=1, month=1, year=2000):
self.day = day
self.month = month
self.year = year
@classmethod
def from_string(cls, date_str):
"""模擬重載構(gòu)造函數(shù) - 從字符串創(chuàng)建"""
day, month, year = map(int, date_str.split('/'))
return cls(day, month, year)
@classmethod
def from_timestamp(cls, timestamp):
"""模擬重載構(gòu)造函數(shù) - 從時(shí)間戳創(chuàng)建"""
# 實(shí)現(xiàn)時(shí)間戳轉(zhuǎn)換邏輯
return cls(1, 1, 2000) # 簡(jiǎn)化示例
# 使用不同的"構(gòu)造函數(shù)"
d1 = Date() # 默認(rèn)構(gòu)造
d2 = Date(15, 12, 2023) # 參數(shù)化構(gòu)造
d3 = Date.from_string("25/12/2023") # 工廠方法
d4 = Date.from_timestamp(1700000000)模擬 RAII (資源獲取即初始化)
Python 使用上下文管理器模擬:
# C++ RAII 風(fēng)格
class FileHandler:
def __init__(self, filename, mode='r'):
self.file = open(filename, mode)
print(f"File {filename} opened")
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.file.close()
print("File closed")
def read(self):
return self.file.read()
# 使用(類(lèi)似C++的確定性析構(gòu))
with FileHandler("test.txt") as fh:
content = fh.read()
# 離開(kāi) with 塊自動(dòng)關(guān)閉文件實(shí)際示例對(duì)比
完整的類(lèi)設(shè)計(jì)對(duì)比
C++:
class BankAccount {
private:
std::string owner;
double balance;
static int accountCount; // 靜態(tài)成員
public:
// 構(gòu)造函數(shù)
BankAccount(const std::string& name, double initialBalance = 0.0)
: owner(name), balance(initialBalance) {
accountCount++;
std::cout << "Account created for " << owner << std::endl;
}
// 拷貝構(gòu)造函數(shù)
BankAccount(const BankAccount& other)
: owner(other.owner + " (copy)"), balance(other.balance) {
accountCount++;
std::cout << "Account copied" << std::endl;
}
// 析構(gòu)函數(shù)
~BankAccount() {
accountCount--;
std::cout << "Account for " << owner << " destroyed" << std::endl;
}
// 成員函數(shù)
void deposit(double amount) {
balance += amount;
}
static int getAccountCount() {
return accountCount;
}
};
int BankAccount::accountCount = 0;Python:
class BankAccount:
_account_count = 0 # 類(lèi)變量(類(lèi)似靜態(tài)成員)
def __init__(self, name, initial_balance=0.0):
self.owner = name
self.balance = initial_balance
BankAccount._account_count += 1
print(f"Account created for {self.owner}")
def __del__(self):
BankAccount._account_count -= 1
print(f"Account for {self.owner} destroyed")
def deposit(self, amount):
self.balance += amount
@classmethod
def get_account_count(cls):
return cls._account_count
# Python 沒(méi)有內(nèi)置的拷貝構(gòu)造,但可以添加一個(gè)方法
@classmethod
def from_existing(cls, existing_account, new_name):
"""模擬拷貝構(gòu)造"""
new_account = cls(new_name, existing_account.balance)
return new_account總結(jié)
__init__≈ 構(gòu)造函數(shù):都用于對(duì)象初始化__del__≈ 析構(gòu)函數(shù):都用于清理,但調(diào)用時(shí)機(jī)不同- 主要差異:
- C++ 有確定的構(gòu)造/析構(gòu)時(shí)機(jī),Python 依賴(lài)?yán)厥?/li>
- C++ 默認(rèn)值語(yǔ)義,Python 默認(rèn)引用語(yǔ)義
- C++ 支持構(gòu)造函數(shù)重載,Python 使用默認(rèn)參數(shù)和類(lèi)方法模擬
- C++ 有專(zhuān)門(mén)的拷貝/移動(dòng)構(gòu)造函數(shù),Python 需要手動(dòng)處理
理解這些差異有助于在兩種語(yǔ)言間轉(zhuǎn)換思維,但要注意它們的設(shè)計(jì)哲學(xué)和內(nèi)存管理機(jī)制有很大不同。
到此這篇關(guān)于C++ 構(gòu)造函數(shù)和析構(gòu)函數(shù)示例詳解的文章就介紹到這了,更多相關(guān)C++ 構(gòu)造函數(shù)和析構(gòu)函數(shù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- C++修煉之構(gòu)造函數(shù)與析構(gòu)函數(shù)
- 正確理解C++的構(gòu)造函數(shù)和析構(gòu)函數(shù)
- C++構(gòu)造函數(shù)和析構(gòu)函數(shù)的使用與講解
- C++中構(gòu)造函數(shù)與析構(gòu)函數(shù)的調(diào)用順序詳解
- 詳解C++中如何將構(gòu)造函數(shù)或析構(gòu)函數(shù)的訪問(wèn)權(quán)限定為private
- C++類(lèi)成員構(gòu)造函數(shù)和析構(gòu)函數(shù)順序示例詳細(xì)講解
- c++基礎(chǔ)語(yǔ)法:構(gòu)造函數(shù)與析構(gòu)函數(shù)
相關(guān)文章
詳解如何將Spire.Doc for C++集成到C++程序中
Spire.Doc for C++是一個(gè)專(zhuān)業(yè)的Word庫(kù),供開(kāi)發(fā)人員在任何類(lèi)型的C++應(yīng)用程序中閱讀、創(chuàng)建、編輯、比較和轉(zhuǎn)換 Word 文檔,本文演示了如何以?xún)煞N不同的方式將 Spire.Doc for C++ 集成到您的 C++ 應(yīng)用程序中,希望對(duì)大家有所幫助2023-05-05
c語(yǔ)言使用fdk_aac實(shí)現(xiàn)aac音頻解碼為pcm
這篇文章主要為大家詳細(xì)介紹了c語(yǔ)言如何使用fdk_aac庫(kù)實(shí)現(xiàn)aac音頻解碼為pcm的功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-11-11
C++實(shí)現(xiàn)簡(jiǎn)單FTP客戶(hù)端軟件開(kāi)發(fā)
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)簡(jiǎn)單FTP客戶(hù)端軟件開(kāi)發(fā),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08
C++標(biāo)準(zhǔn)庫(kù)實(shí)現(xiàn)WAV文件讀寫(xiě)的操作
本文將使用標(biāo)準(zhǔn)C++庫(kù)實(shí)現(xiàn)對(duì)數(shù)據(jù)為PCM格式的WAV文件的讀寫(xiě)操作,只使用標(biāo)準(zhǔn)C++庫(kù)函數(shù),不依賴(lài)于其他的庫(kù),對(duì)C++標(biāo)準(zhǔn)庫(kù)實(shí)現(xiàn)WAV文件讀寫(xiě)相關(guān)知識(shí)感興趣的朋友一起看看吧2022-01-01
C++的靜態(tài)聯(lián)編和動(dòng)態(tài)聯(lián)編
本文闡述了靜態(tài)聯(lián)編和動(dòng)態(tài)聯(lián)編的概念和區(qū)別,通過(guò)具體實(shí)例分析了實(shí)現(xiàn)動(dòng)態(tài)聯(lián)編的條件,指出了虛函數(shù)是實(shí)現(xiàn)動(dòng)態(tài)聯(lián)編的基礎(chǔ)。2016-03-03
深入探究C/C++中互斥量(鎖)的實(shí)現(xiàn)原理
? 互斥量是一種同步原語(yǔ),用于保護(hù)多個(gè)線程同時(shí)訪問(wèn)共享數(shù)據(jù),互斥量提供獨(dú)占的、非遞歸的所有權(quán)語(yǔ)義,本文將和大家一起深入探究C/C++中互斥量(鎖)的實(shí)現(xiàn)原理,感興趣的小伙伴跟著小編一起來(lái)看看吧2024-06-06
解析C++中的虛擬函數(shù)及其靜態(tài)類(lèi)型和動(dòng)態(tài)類(lèi)型
虛擬函數(shù)(Visual Function)亦常被成為虛函數(shù),是C++中的一個(gè)重要特性,本文我們就來(lái)解析C++中的虛擬函數(shù)及其靜態(tài)類(lèi)型和動(dòng)態(tài)類(lèi)型2016-06-06

