Thread: composition, i think

  1. #1
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266

    composition, i think

    hey all, hope you're doing well

    if i use a member function f_x of class x in a member function f_y of class y, do i need to declare member function f_x in class y? if so, how? is this composition? here's the error i'm getting:

    game.obj : error LNK2001: unresolved external symbol "public: void __thiscall Game::mf_playerLineup_display(class Player *,class Player *,class Player *,class Player *,class Player *,class Player *,class Player *,class Player *,class Player *,class

  2. #2
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    erm...i dont know much about it, but i would think you only need to declare f_y in class y under public....i dunno, dont ask me

    ...how about a pointer to the function?

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    declare f_x as a public function of class X. make sure you include X's header in Y so that it knows it exists... then you can do this;

    Code:
    void Y::f_y(void)
    {
       X x;
       x.f_x();
    }
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  4. #4
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    hey thanks all,

    i got it to work but by declaring f_x in X like any other member function, it seems to work fine. which makes me think that this is not what my book calls composition. the book's example delt with data members, not functions, and also gave this odd constructor syntax:

    Code:
    X::x (int a, int b, int c)
      :yData1_ofclass_x (int a, intb, int c)
      :yData2_ofclass_x (int a, int b, int c)
    
    {
    // . . . 
    
    yData1_ofclass_x.x_function();
    if anyone can explain what the deal is with that constructor, i'd appreciate it. it came from pg 462, deitel & deitel 3rd ed.

    thanks again guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-10-2007, 03:51 PM
  2. Composition & Aggregration
    By aldajlo in forum C++ Programming
    Replies: 1
    Last Post: 10-26-2004, 03:39 PM
  3. Need help with Composition
    By cuddlez.ini in forum C++ Programming
    Replies: 3
    Last Post: 10-25-2004, 08:28 PM
  4. difference between aggregation and composition
    By anil_beloved in forum C Programming
    Replies: 1
    Last Post: 10-18-2004, 12:17 PM
  5. Inheritance vs Composition
    By Panopticon in forum C++ Programming
    Replies: 11
    Last Post: 01-20-2003, 04:41 AM