Re: How do I access another type's method from one type's method

Discussion in 'C++' started by Rolf Magnus, Jul 3, 2003.

  1. Rolf Magnus

    Rolf Magnus Guest

    ding feng wrote:

    > I got this program:
    >
    > class building{
    > ...
    > };
    >
    > class school:public building{
    > ...
    >
    > int getstudentnumber(int m);
    > };
    >
    > class hospital:public building{
    > ...
    >
    > int reportpatientnumber();
    > };
    >
    > int hospital:reportpatientnumber()
    > {
    > //here I need to call school method getstudentnumber(int m);


    A hospital is not a school, so you can't call school's member functions
    for a hospital. Or did I misunderstand something?

    > }
    >
    > In hosptial:reportpatientnumber() method, I can't pass anything as a
    > parameter, for example, can't pass a school type pointer. The
    > parameter lists MUST be empty.


    What does the int parameter do?

    > Is there an alternative way to do that?


    It's hard to tell from the information you provided.
    Rolf Magnus, Jul 3, 2003
    #1
    1. Advertising

  2. Rolf Magnus

    ding feng Guest

    Rolf Magnus <> wrote in message news:<be2c9e$kre$07$-online.com>...
    > ding feng wrote:
    >
    > > I got this program:
    > >
    > > class building{
    > > ...
    > > };
    > >
    > > class school:public building{
    > > ...
    > >
    > > int getstudentnumber(int m);
    > > };
    > >
    > > class hospital:public building{
    > > ...
    > >
    > > int reportpatientnumber();
    > > };
    > >
    > > int hospital:reportpatientnumber()
    > > {
    > > //here I need to call school method getstudentnumber(int m);

    >
    > A hospital is not a school, so you can't call school's member functions
    > for a hospital. Or did I misunderstand something?
    >
    > > }
    > >
    > > In hosptial:reportpatientnumber() method, I can't pass anything as a
    > > parameter, for example, can't pass a school type pointer. The
    > > parameter lists MUST be empty.

    >
    > What does the int parameter do?
    >
    > > Is there an alternative way to do that?

    >
    > It's hard to tell from the information you provided.


    In the main, I got to do this:
    int hospital1.reportpatientnumber()
    {
    conditions...
    case(condition1)
    return school1.getstudentnumber(50);
    case(condition2)
    return shcool2.getstudentnumber(20);
    ....
    }

    Obviously, the compiler will complain. I don't know how to do that.

    Also, if school type is declared after hospital type, then compiler
    complain undefined type. Even I use forward declaration, it also
    doesn't work. Compiler still complains undefined type.
    ding feng, Jul 4, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. qwerty
    Replies:
    3
    Views:
    9,278
    Scott Allen
    Sep 30, 2004
  2. Magne Bergfjord
    Replies:
    1
    Views:
    453
  3. loveNUNO
    Replies:
    2
    Views:
    907
    loveNUNO
    Nov 20, 2003
  4. Howard
    Replies:
    2
    Views:
    372
    Michiel Salters
    Jul 4, 2003
  5. Robert Cohen
    Replies:
    3
    Views:
    265
    Andrew Durstewitz
    Jul 15, 2003
Loading...

Share This Page