为什么最后面的pcx->x*=n; 不能写成(pcx.x)*=n; ?

[复制链接]
查看11 | 回复1 | 2010-8-20 00:38:37 | 显示全部楼层 |阅读模式
#include
#include
using namespace std;
struct complex_int
{
int x;
int y;
};
void print_cx(complex_int cx);
double calc_abs(const complex_int &cx);
void expand(complex_int *pcx,int n);
int main()
{
complex_int cnum1={1,2};
int n=4;
coutx*=n;
pcx->y*=n;
}

回复

使用道具 举报

千问 | 2010-8-20 00:38:37 | 显示全部楼层
因为参数 complex_int *pcx, 是指针。要写 pcx->x *= n;如果参数是 complex_int pcx, 不是指针,要写 (pcx.x) *= n; double res=sqrt((cx.x*cx.x+cx.y*cx.y));//为什么要两层括号?大概表示一个参数,看起来清楚,可以用1层。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行