how to import a function from one file to code example

Example 1: python use functions from another file

#If you want to import all functions from file... but you will still need to
#mention the file name:
import pizza
pizza.pizza_function()

#If you want to import every function but you dont want to mention file name:
from pizza import *
pizza.pizza_function()

Example 2: defining function in other file

//Your .h file..
#ifndef MY_HEADER
#define MY_HEADER
 int add(int, int);
#endif 

//main.cpp
#include "myHeader.h"

int main()
{
  int result = add(1,2);
  return 0;
}

//file that contain definition of the functions...
//.cpp
#include "myHeader.h"

int add(int a, int b)
{
 return a+b;
}

Tags:

Cpp Example