一、普通函數的重載
# includeusing namespace std; void func(int); void func(float); void func(double); int main() { int a=4; float b=3.1; double c=3.1234; cout<<"a的值為:"<
運行結果:
二、成員函數的重載<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PC9wPgo8cHJlIGNsYXNzPQ=="brush:java;"># include
using namespace std; class cube { public: void sum(); void sum(int i,int j); private: int x; int y; }; int main() { cube a; a.sum(2,3); a.sum(); return 0; } void cube::sum() { cout<<"x的立方為:"<
三、構造函數的重載
# includeusing namespace std; class rectangel { public: rectangel(){cout<<"構造一個長方形a!\n";} rectangel(int l,int w){length=l;width=w;cout<<"長方形的面積為:"<
運行結果: