Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Defining functions in other files

Defining functions in other files

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    satcat
    wrote on last edited by
    #1

    Hi there! I have to use some functions in my application but they must be in an apart file because they are going to be used from differents applications. How should I write it in my code so it runs? What headers should I add to my code? Thank you in advance!

    D 1 Reply Last reply
    0
    • S satcat

      Hi there! I have to use some functions in my application but they must be in an apart file because they are going to be used from differents applications. How should I write it in my code so it runs? What headers should I add to my code? Thank you in advance!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Put the declaration of the function(s) in a .H file. Put the definition of the function(s) in a .C or .CPP file. Whenever you need to use one of the functions, simply include the appropriate .H file. To keep the linker from complaining about multiply-defined symbols, you'll need something like the following at the top of each .H file:

      #if !defined(some_unique_symbol_here)
      #define some_unique_symbol_here
      #pragma once

      ...

      #endif


      A rich person is not the one who has the most, but the one that needs the least.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups