刚学C++,遇到一个问题,希望大家帮忙解答一下!
#include <iostream.h>
#define SR struct Rect
struct Rect
{
int m_nLeft;
int m_nTop;
int m_nRight;
int m_nBottom;
};
int CreateRect(SR *crect,int nLeft,int nTop,int nRight,int nBottom)
{
crect.m_nLeft=nLeft;
return 1;
}
void main()
{
SR rect;
cout<<"是否创建一个矩形!"<<endl;
CreateRect(&rect,10,10,20,20);
}
编译后有个错误:
error C2228: left of '.m_nLeft' must have class/struct/union type
问题点数:0、回复次数:6Top
1 楼steedhorse(晨星)回复于 2005-04-03 19:06:08 得分 0
通过指针不能使用"."存取成员,应该是用:"->"。Top
2 楼steedhorse(晨星)回复于 2005-04-03 19:06:37 得分 0
crect->m_nLeft=nLeft;Top
3 楼answersha(水少爷)回复于 2005-04-03 19:22:04 得分 0
指针用 ->
Top
4 楼runall(龙行天下)回复于 2005-04-03 19:29:14 得分 0
crect是指针,调用其成员应该用->Top
5 楼Kyori_YR()回复于 2005-04-03 20:17:06 得分 0
谢谢大家!Top
6 楼MagicCarmack(MagiC++)回复于 2005-04-03 20:36:09 得分 0
crect.m_nLeft=nLeft;//crect is a pointer
crect->m_nLeft=nLeft;//okTop




