zoukankan      html  css  js  c++  java
  • C++学习札记(2)

    重载构造函数

    #include <iostream>

    using namespace std;

    class rectangle

    {

    public:

         rectangle(){cout<<"构造一个长方形a! ";}                                          // 无参数的构造函数

         rectangle(int l,int v){length=l;width=w;cout<<"长方形b的面积为:“

         rectangle(int l,int v,int h){length=l,width=w;height=h;cout<<"长方形的..."}       //  将 l、v、h赋值给私有变量 length、width、height

    private:

         int length;

         int width;

         int height;

    }

    int main()

    {

       rectangle a;

       rectangle b(3,4);

       rectangle c(3,4,10);

       return 0;

    }

    以上说明了构造函数,以及通过公有成员 调用 私有成员的方法。

    栈和堆的不同:

    1.栈由系统自动分配内存,堆要程序员进行申请;

    2.栈中空间比较小,只有2M,对的上限是由系统中有效的虚拟内存来定的。因此获得的空间比较大。

  • 相关阅读:
    「CH6801」棋盘覆盖
    「POJ3613」Cow Relays
    「Luogu4556」Vani有约会-雨天的尾巴
    The Proof of Fibonacci GCD
    Ubuntu flatabulous 主题
    CSP-S 2019 复赛游记
    「Luogu1402」酒店之王
    HDU/5499/模拟
    cfedu/A/求和
    HDU<1372>/bfs
  • 原文地址:https://www.cnblogs.com/ruoke9/p/4893238.html
Copyright © 2011-2022 走看看