Calling a function before it exists

This is a discussion on Calling a function before it exists within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm making a Static Library that calls a function that does not yet exists, but is defined by the ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640

    Calling a function before it exists

    Hi,

    I'm making a Static Library that calls a function that does not yet
    exists, but is defined by the program that uses the library.
    How can i accomplish this? I know it's possible with DLL's, but
    that's not what i want.

    Thx in advanced.

  2. #2
    Registered User SubLogic's Avatar
    Join Date
    Jan 2003
    Posts
    33
    I didn't really understand you but this may help: (I hope)


    Wrong
    Code:
    int main()
    {
      myfunction(5,3);
      return 0;
    }
    
    int myfunction(int param1, int param2)
    {
      lalalala;
      return 0;
    }

    Right (Except for the lalala thingey :P)
    Code:
    int myfunction(int, int)
    
    int main()
    {
      myfunction(5,3);
      return 0;
    }
    
    int myfunction(int param1, int param2)
    {
      lalalala;
      return 0;
    }

    Tell me if this is what you meant.
    0100001

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    No, fun though to be treated like a beginner .
    What you posted is for the compiler to know that this function
    exists before it stumbled across it's definition. What i ment
    was that it called a function from another yet to be coded
    source code.

    the library:

    Code:
    void blab();
    
    void blob()
    {
    blab();
    }
    the source that is created after the library has been compiled

    Code:
    void blab()
    {
    }

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Originally posted by Salem
    you pass the function to be called as a parameter to some call into the library.
    Could you go more into this?

  5. #5
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Or, why not just use polymorphism. We're not limitted to C anymore, remember?

    Define a base class with a virtual member function and make children in another project.

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    You're able to have a pointer to a function?
    Aren't you able to tell the lib wich function to run?
    Then it's all solved isn't it?
    Last edited by Travis Dane; 01-21-2003 at 01:20 PM.

  7. #7
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343

  8. #8
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Originally posted by ripper079
    Try this one
    I just love a google search
    Yeah, i removed the tutorial request because i thought i was getting like
    alot of other people here, requesting before searching, sorryz.

    Thx for such a specific tutorial though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  4. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  5. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21