设为首页 加入收藏

TOP

const用法详解
2014-11-14 21:45:25 来源: 作者: 【 】 浏览:16
Tags:const 用法 详解

  当不想从外部调用成员函数修改成员变量时,可以将其被调成员函数加上const每个成员函数都有个隐式 this 指针,指向调用对象


  代码


  1 // CBox类头文件


  2 #pragma once


  3 #include


  4 using namespace std;


  5


  6 class CBox


  7 {


  8 public:


  9   CBox(double lv = 1.0, double lw = 1.0, double lh = 1.0);


  10


  11 public:


  12 double Volume( void ) const;


  13 int Compare( CBox xBox ) const;


  14


  15 private:


  16 double m_Length;


  17 double m_Width;


  18 double m_Height;


  19 };


  20


  21 // CBox类源文件


  22 #include "Box.h"


  23


  24 //构造函数


  25 CBox::CBox(double lv, double lw, double lh) 26   : m_Length(lv),m_Width(lw),m_Height(lh)


  27 {


  28 cout << "构造函数" << endl;


  29 }


  30


  编辑推荐:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇windows编程:指针与引用 下一篇VC中使用数学常量M_PI

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: