Calling a class' memver function from inside another class

Discussion in 'C++' started by philipwinder@googlemail.com, Aug 3, 2006.

  1. Guest

    Hi, im a bit stuck with a little problem. I have created two classes,
    CDrawControl and CSoundControl, and I have first created a CDrawControl
    object and then a CSoundControl. The problem is that I am trying to
    call a function within CDrawControl from within CSoundControl but it
    causes errors. How can I get around this?

    Just to reitoriate:

    CDrawControl oMyDrawControl;
    CSoundControl oMySoundControl;
    .......

    // From within oMySoundControl class
    ...
    oMyDrawControl:Somefunction();
    ...

    Many thanks,

    Phil Winder
    , Aug 3, 2006
    #1
    1. Advertising

  2. wrote:
    > Hi, im a bit stuck with a little problem. I have created two classes,
    > CDrawControl and CSoundControl, and I have first created a
    > CDrawControl object and then a CSoundControl. The problem is that I
    > am trying to call a function within CDrawControl from within
    > CSoundControl but it causes errors.


    What errors? I don't see no errors...

    > How can I get around this?


    Around what?

    > Just to reitoriate:
    >
    > CDrawControl oMyDrawControl;
    > CSoundControl oMySoundControl;
    > .......
    >
    > // From within oMySoundControl class
    > ...
    > oMyDrawControl:Somefunction();


    That's not the right syntax. Do you mean

    oMyDrawContro.Somefunction();

    ?


    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Aug 3, 2006
    #2
    1. Advertising

  3. schrieb:
    > Hi, im a bit stuck with a little problem. I have created two classes,
    > CDrawControl and CSoundControl, and I have first created a CDrawControl
    > object and then a CSoundControl. The problem is that I am trying to
    > call a function within CDrawControl from within CSoundControl but it
    > causes errors. How can I get around this?
    >
    > Just to reitoriate:
    >
    > CDrawControl oMyDrawControl;
    > CSoundControl oMySoundControl;
    > .......
    >
    > // From within oMySoundControl class
    > ...
    > oMyDrawControl:Somefunction();
    > ...


    As you don't want to show us your real code along with the class
    definitions, not even you error messages, I have to guess:

    1) You have a ":" where you should have a "."

    Try: oMyDrawControl.Somefunction();

    2) You try to call a member function that is not public.

    However, you should study the FAQ, that would help a lot:
    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8

    --
    Thomas
    Thomas J. Gritzan, Aug 3, 2006
    #3
  4. Phil Winder Guest

    Sorry, yes you are right I did mean:

    oMyDrawControl.Somefunction();

    Just a typo, the error it just the same. Also, I didnt think it
    requires full code because I thought was just inexperience, hence the
    following snippit.

    CDrawControl oMyDrawControl;
    CSoundControl oMySoundControl;
    .......

    // From within oMySoundControl class
    ...
    oMyDrawControl.Somefunction();
    ...

    error C2065: 'oMyDrawControl' : undeclared identifier
    error C2228: left of '.DrawSpectrum' must have class/struct/union
    Phil Winder, Aug 4, 2006
    #4
  5. Phil Winder wrote:
    > Sorry, yes you are right I did mean:
    >
    > oMyDrawControl.Somefunction();
    >
    > Just a typo, the error it just the same. Also, I didnt think it
    > requires full code because I thought was just inexperience, hence the
    > following snippit.
    >
    > CDrawControl oMyDrawControl;
    > CSoundControl oMySoundControl;
    > .......
    >
    > // From within oMySoundControl class
    > ...
    > oMyDrawControl.Somefunction();
    > ...
    >
    > error C2065: 'oMyDrawControl' : undeclared identifier
    > error C2228: left of '.DrawSpectrum' must have class/struct/union


    Please post a short piece of compilable code that will allow us to
    duplicate the problem. Until you do that, we can't help you. Please
    look at the FAQ you were referred to before.

    Good luck.

    Best regards,

    Tom
    Thomas Tutone, Aug 4, 2006
    #5
  6. Phil Winder Guest

    I was going to write a rant, but i decided to delete it and just say
    that can people please write in a mannor in which they would talk to
    others, since patronising is actually quite offensive.

    All I wanted to know was, was that syntax correct, the ideas behind it
    right and it should have been a quick 5 second answer.

    Ive decided to go another way and figured out another way.

    Thanks anyway,

    Phil Winder
    Phil Winder, Aug 6, 2006
    #6
    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. nail
    Replies:
    0
    Views:
    1,529
  2. Andreas Lagemann
    Replies:
    8
    Views:
    465
    Mike Wahler
    Jan 10, 2005
  3. tiwy
    Replies:
    0
    Views:
    431
  4. Yigit Turgut
    Replies:
    5
    Views:
    186
    Terry Reedy
    Jan 10, 2012
  5. Sur
    Replies:
    4
    Views:
    178
Loading...

Share This Page