您的位置:首页 > 移动开发 > Objective-C

const at the end of function and passing const object in a function call

2009-01-23 13:45 621 查看
#include <ostream.h>

Class B

{

public:

virtual void print() const

{

cout << "printB" << std::endl;

}

};

class A

{

public:

virtual void print(const B* b) const

{

cout << "printA" << std::endl;
b->print();

}

};

main()

{

cout << "test" << std::endl;

A* a;

B* b;

a = new A();

b = new B();

a->print(b);

}

Note:

1. the const at the end of the function declaration: indicates that the "this" parameter to the function is const.

2. use the const because it don't modify the object.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐