zoukankan      html  css  js  c++  java
  • 类的数据成员加前缀 m_(表示 member)

    类的数据成员加前缀 m_(表示 member),这样可以避免数据成员与 成员函数的参数同名。

    例如: void Object::SetValue(int width, int height) { m_width = width; m_height = height; }

     1 #include <iostream>
     2 #include <stdlib.h>
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 
     5 using namespace std;
     6 //定义timer类
     7 class timer{  
     8     long minutes;
     9 public:
    10     //定义重载成员函数
    11     settimer(char *m) { 
    12         minutes = atoi(m);
    13     };
    14     //定义重载成员函数
    15     settimer(int h, int m) { 
    16         minutes = 60*h+m ;
    17     };
    18     //定义重载成员函数
    19     settimer(double h) { 
    20         minutes = (int) 60*h ;
    21     };
    22     long getminutes(void) { return minutes; };
    23 };
    24 
    25 int main(int argc, char** argv) {
    26       timer start,finish;   //创建对象
    27 
    28     //使用重载成员函数
    29     start.settimer(8,30);
    30     finish.settimer(9,40); 
    31     cout<<"finish.settimer(9,40)-start.settimer(8,30):";
    32     cout<<finish.getminutes()-start.getminutes()<<endl;  
    33 
    34     //使用重载成员函数
    35     start.settimer(2.0);
    36     finish.settimer("180"); 
    37     cout<<"finish.settimer("180")-start.settimer(2.0):";
    38     cout<<finish.getminutes()-start.getminutes()<<endl;  
    39     return 0;
    40 }
  • 相关阅读:
    转C#与CSV
    转Log4Net配置
    转sp_addlinkedserver实现远程数据库链接
    HTML DOM
    JavaScript学习
    2016年的个人计划-xiangjiejie
    sass转换为css
    返回上一页显示上次操作后的界面
    angular ng-bind-html 对src路径失效 解决方案
    angular json转义html
  • 原文地址:https://www.cnblogs.com/borter/p/9413443.html
Copyright © 2011-2022 走看看