由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - which func will be called?
相关主题
问题c++ 得最基本问题
问个C++ virtual function的问题 (转载)C++ 的 问题
为什么foo1可以而foo2不行?A aimple C++ question
question regarding const function关于C++ copy-constructor 一个奇怪的问题
[合集] C++问题(copy constructor)conversion between const to nonconst
小问题关于const_cast,地址一样,值不同?
请教各路C++大神 为什么f(3) 输出是 'dd'question about c++ constructor
关于C++中一个Class的大小 (转载)编译器如何分辨返回类型不同的函数?
相关话题的讨论汇总
话题: func话题: void话题: const话题: called话题: test
进入Programming版参与讨论
1 (共1页)
s**i
发帖数: 381
1
Suppose I have the following class:
class test{
public:
void func() const
{
cout<<"hello,func const"< }
void func()
{
cout<<"hello,func"< }
};
when A is an object of test.
What will A.func() give me?
My test says always the "hello,func" but I don't know why.
Thanks
P*****x
发帖数: 72
2
what if you reverse the sequence of definition?
I guess this is compiler specific. Your object is
not changed in either case and the declaration of
the second one is wrong.

【在 s**i 的大作中提到】
: Suppose I have the following class:
: class test{
: public:
: void func() const
: {
: cout<<"hello,func const"<: }
: void func()
: {
: cout<<"hello,func"<
K*****n
发帖数: 65
3
when a member function is called, "this" pointer is implicitly passed as
argument.It is part of function signature. Therefore
void func() const;//say "*this" will not be changed.
void func(); //"*this" may or may not be changed.
void main()
{
test a;
a.func(); //call void func();
((const A)a).func(); //call void func() const;
(*(const A *)&a).func(); //call void func() const;
}

【在 s**i 的大作中提到】
: Suppose I have the following class:
: class test{
: public:
: void func() const
: {
: cout<<"hello,func const"<: }
: void func()
: {
: cout<<"hello,func"<
1 (共1页)
进入Programming版参与讨论
相关主题
编译器如何分辨返回类型不同的函数?[合集] C++问题(copy constructor)
member and friend小问题
namespace 问题请教各路C++大神 为什么f(3) 输出是 'dd'
请问这个C++程序有什么问题吗关于C++中一个Class的大小 (转载)
问题c++ 得最基本问题
问个C++ virtual function的问题 (转载)C++ 的 问题
为什么foo1可以而foo2不行?A aimple C++ question
question regarding const function关于C++ copy-constructor 一个奇怪的问题
相关话题的讨论汇总
话题: func话题: void话题: const话题: called话题: test