【发布时间】:2010-12-30 13:58:58
【问题描述】:
谁能告诉我(*ptr).field 和ptr->field 有什么区别?
我知道它以某种方式连接到静态和动态链接,但我不知道它是什么。
谁能告诉我不同之处并举个例子?
编辑: 如果我有这个代码:
Point p; //point is a class that derive from class shape
Shape *s=&p;
//there is a diffrence if i write:
(*s).print(); //print is virtual func
s->print(); // the answers will not be the same, why?
TNX!
【问题讨论】:
-
您的意思是
(*ptr).field还是*ptr.field?如果你的意思是*ptr.field,那么这两种形式根本没有任何共同之处,这使得这个问题几乎没有意义。 -
根据您的编辑:答案是一样的。见下文。
-
我不知道您在代码示例中所指的“答案”是什么,但在您的代码示例中,两个调用都会完全相同。它们之间绝对没有区别。
-
@aharont:您发布的代码没有说明差异。请发布一个完整的最小测试用例,它应该可以按原样编译。因此,它应该包括
Shape和Point的最少定义。它也应该是一个新问题,因为新问题不同于“(*ptr).field 和 ptr->field 之间有什么区别?”
标签: c++ operators operator-precedence