productclassnested.cpp

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

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

class product 
{     
    class value
    {
    public:
        int internal_value;
        int get_value(){return internal_value;}
        void set_value(int n){internal_value = n;}
    };
    value number;        
public:         
    string name;              
    int get_number(){return number.get_value();}
    void set_number(int n){number.set_value(n);}
    product(string text, int count);
};

product::product(string text, int count)
{
    number.set_value(count);
    name = text;
}

int main()
{
    product oranges("oranges", 200);

    cout << "Number of " << oranges.name << ": " << oranges.get_number() << endl;

    return 0;
}


⌨️ 快捷键说明

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