Ya, the compiler is right (obviously it had to be
right)

The statement: 
pizza * guest = new pizza[quantity];

allocates an array of pizza and makes guest pointer
point to it.
Therefore guest[i] is not a pointer but a pizza
element.
Therefore use the dot (.) operator instead of ->

guest[i].name ....

Regards
Manik


--- Hardy Huang <[EMAIL PROTECTED]> wrote:

> It is a compiler error.
> It says:
> 
> base operand of `->' has non-pointer type `pizza'
> 
> 
> At 01:33 AM 1/2/2005, you wrote:
> 
> 
> >--- Hardy Huang <[EMAIL PROTECTED]> wrote:
> >
> > >
> > > Hai,
> > >       I'm trying to use pointer, array and
> struct
> > > together. I'm a newbie.
> > > Here is my code. I still don't know what's wrong
> > > with it. So guys plz help
> > > me out.
> > >
> > > #include <iostream>
> > > using namespace std;
> > > #include <conio.h>
> > >
> > > const int nameSize = 20;
> > > struct pizza
> > > {
> > >      char name[nameSize];
> > >      float diameter;
> > >      float weight;
> > > };
> > >
> > > int main()
> > > {
> > >      cout << "Welcome to William Wingate Pizza
> > > Analysis Service!\n";
> > >      cout << "How many pizza do you want to
> > > make?\n";
> > >
> > >      /////////////////
> > >      int quantity;
> > >      (cin >> quantity).get();
> > >      pizza * guest=new pizza[quantity];
> > >      /////////////////
> > >
> > >
> > >
>
>///////////////////////////////////////////////////////////
> > >      for (int i=1; i<=quantity; i++)
> > >      {
> > >          cout << "Enter number " << i << " pizza
> > > statistics!\n";
> > >          cout << "Enter pizza name     : ";
> > >          cin.getline(guest[i]->name,nameSize);
> > >          cout << "Enter pizza diameter : ";
> > >          cin >> guest[i]->diameter;
> > >          cout << "Enter pizza weight   : ";
> > >          (cin >> guest[i]->weight).get();
> > >      }
> > >
> > >
>
>///////////////////////////////////////////////////////////
> > >      cout << "\nHere is your pizza
> statistics!\n";
> > >
> > >
>
>///////////////////////////////////////////////////////////
> > >      for (int i=1; i<=quantity; i++)
> > >      {
> > >          cout << "Pizza number " << i << endl;
> > >          cout << "Name     : " << guest[i]->name
> <<
> > > endl;
> > >          cout << "Diameter : " <<
> guest[i]->diameter
> > > << endl;
> > >          cout << "Weight   : " <<
> guest[i]->weight
> > > << endl;
> > >      }
> > >
> > >
>
>///////////////////////////////////////////////////////////
> > >      getch();
> > >      return 0;
> > > }
> > >
> > > Thank you and Happy New Year
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >Hi Binit,
> >
> >Firstly you didnt mention what problem are you
> facing
> >with the code.. (compiler error.. runtime error? )
> >
> >The loop range you are using is from 1 to
> <quantity>.
> >It should be from 0 to <quantity -1>.
> >
> >Regards
> >Manik
> >
> >
> >
> >
> >__________________________________
> >Do you Yahoo!?
> >Send holiday email and support a worthy cause. Do
> good.
>
><http://celebrity.mail.yahoo.com>http://celebrity.mail.yahoo.com
> >
> >
> >
> >
> >
> >To unsubscribe :
> [EMAIL PROTECTED]
> >
> >
> >
> >
> >
> >----------
> >Yahoo! Groups Links
> >    * To visit your group on the web, go to:
> >    * 
> >
>
<http://groups.yahoo.com/group/Programmers-Town/>http://groups.yahoo.com/group/Programmers-Town/
> 
> >
> >    *
> >    * To unsubscribe from this group, send an email
> to:
> >    * 
> >
>
<mailto:[EMAIL PROTECTED]>[EMAIL PROTECTED]
> 
> >
> >    *
> >    * Your use of Yahoo! Groups is subject to the 
> > <http://docs.yahoo.com/info/terms/>Yahoo! Terms of
> Service.
> 
> 
>
*************************************************************************
> Laughing at our mistakes can lengthen our own life.
> Laughing at someone else's can shorten it.
> 
> ---Cullen Hightower---
>
************************************************************************
> 



                
__________________________________ 
Do you Yahoo!? 
Send holiday email and support a worthy cause. Do good. 
http://celebrity.mail.yahoo.com





To unsubscribe : [EMAIL PROTECTED]

 
Yahoo! Groups Links

<*> To reply to this message, go to:
    
http://groups.yahoo.com/group/Programmers-Town/post?act=reply&messageNum=5002
    Please do not reply to this message via email. More information here:
    http://help.yahoo.com/help/us/groups/messages/messages-23.html

<*> To visit your group on the web, go to:  
    http://groups.yahoo.com/group/Programmers-Town/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to