Thread: Calling a member function from a different file

  1. #1
    Registered User cdonlan's Avatar
    Join Date
    Sep 2004

    Calling a member function from a different file

    Hi guys
    Im having some problem calling a member function in my main.cpp file. The class is in a header file and the member function itself is located in an addational cpp file. Im getting a linker error when I compile. I called it with classname::memberfunctio(). If anyone needs to see either of the cpp or the header file let me know. I didnt want to post I didnt need to because they are so big.


  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Well you could try telling us what the linker error is and maybe provide the applicable code - like a shorter version of main that includes the member call.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  3. #3
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Quote Originally Posted by cdonlan
    Maybe his problem is that he's leaving off the last letter of the function

    Some code would really help, so when you get the chance post it.
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    You must include the header that has the prototype for the function and/or the class definition that the function belongs to.

    #ifndef FOO
    #define FOO
    class CFoo 
      int m_iFoo; 
         CFoo(void):m_iFoo(0) {}
         void SetFooFunc(int iNewFoo)  {m_iFoo=iNewFoo;};
    #include "CFoo.h"
    CFoo TestFoo;
    int main(void)
    • MainLoop.cpp

    Normally if you had a header file and a cpp file for CFoo you would add CFoo.cpp to the project. However in this case CFoo is completely defined as inline and so just including the header will suffice.

    This only relates to MSVC 6.
    Last edited by VirtualAce; 02-01-2005 at 12:53 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM