class Ball {
public:
    Ball():_radius{0.0},_name{""}, _index{0.0}{};
    Ball(double _r, const char* p):_radius{_r},_name{p}, _index{0.0}{};
 
    double radius() const {
        return _radius;
    }
    const string& name() const {
        return _name;
    }
    void radius(double radius)  {
        _radius = radius;
    }
    void name(const char *name) {
        _name = name;
    }
    void name(string& name) {
        _name = name;
    }
    double volumn() {
        return (4 / 3 * 3.14159 * _radius * _radius * _radius);
    }
    double increment() const {
        return _index++;
    }
private:
    double _radius;
    string _name;
    mutable double _index;
};
void somefunc(const Ball& ball)
{
    ball.radius() ;
    string s = ball.name() ;
    cout << ball.increment()  << endl ;
    cout << ball.increment()  << endl ;
    cout << ball.increment()  << endl ;
}
int main()
{
    Ball b1(10.0,"BALLX") ;
    somefunc(b1) ;
}

 

From http://openhome.cc/Gossip/CppGossip/constAndmuttable.html

 

arrow
arrow
    全站熱搜

    hedgezzz 發表在 痞客邦 留言(0) 人氣()