birdclassconstmethod.cpp

来自「C++ sample code, for the book: C++ blac」· C++ 代码 · 共 37 行

CPP
37
字号
#include <iostream>
#include <string>
using namespace std;

class bird_class 
{     
private:
    int number_seen;        
public:         
    string name;              
    void increment_count(){number_seen++;}
    bird_class(string text);
    int bird_class::get_number() const;
};

bird_class::bird_class(string text)
{
    name = text;
    number_seen = 1;
}

int bird_class::get_number() const
{
    return number_seen;
}

int main()
{
    const bird_class orioles("oriole");

    cout << "Number of " << orioles.name << "s seen: " << orioles.get_number() << endl;

    return 0;
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?