弱弱地问 ->与.区别

deansroom 2006-04-27 11:02:44
delphi中一律用.发现c++builder中有的地方用-> 有的地方用.
不明白他们的区别
望指点
...全文
109 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
cczlp 2006-04-27
  • 打赏
  • 举报
回复
指针用->, 其它用.

刚学C很容易晕头,Delphi要简单些。
xiaoshi0 2006-04-27
  • 打赏
  • 举报
回复
如果是对象就用.引用成员变量或者方法

如果是对象的指针,就用->引用成员变量或方法
tianshu888 2006-04-27
  • 打赏
  • 举报
回复
一个是指针 一个是引用 如果这个听不明白的话,具体的看看书把。
yz20050510 2006-04-27
  • 打赏
  • 举报
回复
两者有一定的区别,
但是对于我们用户来说,没有区别,
两者都可以调用对象的属性和方法
铖邑 2006-04-27
  • 打赏
  • 举报
回复
object pascal把对象实例处理为普通变量形式,所以都用“.”
C++中,指针用“->”,对象型变量用“.”
lurel 2006-04-27
  • 打赏
  • 举报
回复
不会吧,一,语法不同,二,看看C++面向对象编程.和->的区别
deansroom 2006-04-27
  • 打赏
  • 举报
回复
晕 空贴
hellolongbin 2006-04-27
  • 打赏
  • 举报
回复
deansroom 2006-04-27
  • 打赏
  • 举报
回复
C++ Language Reference

Member Access Operators: . and ->See Also
Postfix Expressions | C++ Operators | Operator Precedence and Associativity | Classes | Structures | and Unions | Structure and Union Members (C Reference)Grammar
postfix-expression :
postfix-expression . name
postfix-expression –> name
The member access operators . and -> are used to refer to members of structures, unions, and classes. Member access expressions have the value and type of the selected member.
There are two forms of member access expressions:
In the first form, postfix-expression represents a value of struct, class, or union type, and name names a member of the specified structure, union, or class. The value of the operation is that of name and is an l-value if postfix-expression is an l-value.
In the second form, postfix-expression represents a pointer to a structure, union, or class, and name names a member of the specified structure, union, or class. The value is that of name and is an l-value. The –> operator dereferences the pointer. Therefore, the expressions e–>member and (*e).member (where e represents a pointer) yield identical results (except when the operators –> or * are overloaded).
Example
The following example demonstrates both forms of the member access operator.
// expre_Selection_Operator.cpp
// compile with: /EHsc
// Demonstrate member access operators
#include <iostream>
using namespace std;
struct Date {
Date(int i, int j, int k) : day(i), month(j), year(k){}
int month;
int day;
int year;
};

int main() {
Date mydate(1,1,1900);
mydate.month = 2;
cout << mydate.month << "/" << mydate.day
<< "/" << mydate.year << endl;

Date *mydate2 = new Date(1,1,2000);
mydate2->month = 2;
cout << mydate2->month << "/" << mydate2->day
<< "/" << mydate2->year << endl;
}
多谢楼上的提醒 xpdavis(咕嘟) 兄的解释似乎最恰当
deansroom 2006-04-27
  • 打赏
  • 举报
回复
呵呵 是正在晕头中正在翻书上的介绍 并比较一些实例的区别 争取自己真的弄懂了再结贴

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧