You must use a tool called a “header”. In a header you declare the function that you want to use. Then you include it in both files. A header is a separate file included using the #include
directive. Then you may call the other function.
other.h
void MyFunc();
main.cpp
#include "other.h" int main() { MyFunc(); }
other.cpp
#include "other.h" #include <iostream> void MyFunc() { std::cout << "Ohai from another .cpp file!"; std::cin.get(); }
Related Posts:
- What is the proper declaration of main in C++?
- ‘foo’ was not declared in this scope c++
- C++ — expected primary-expression before ‘ ‘
- strdup() – what does it do in C?
- strdup() – what does it do in C?
- Return array in a function
- Meaning of = delete after function declaration
- “Parameter” vs “Argument”
- Help needed with Median If in Excel
- PHP Fatal error: Using $this when not in object context
- invalid use of non-static member function
- Reverse Contents in Array
- c++: No instance of overloaded function
- error: expected primary-expression before ‘)’ token (C)
- How do you pass a function as a parameter in C?
- How do you pass a function as a parameter in C?
- error: “initializer expression list treated as compound expression”
- Getting error: ISO C++ forbids declaration of with no type
- Function for C++ struct
- c++ –
- What does it mean that “a declaration shadows a parameter”?
- C++ – statement cannot resolve address for overloaded function
- How do I return a char array from a function?
- How to return a struct from a function in C++?
- Why can’t we pass arrays to function by value?
- template argument deduction/substitution failed, when using std::function and std::bind
- Optional arguments in C function
- How do I use the filter function in Haskell?
- the functions (procedures) in MIPS
- ERROR: Control may reach end of non-void function /
- function does not take 1 arguments c++
- C++ correct way to return pointer to array from function
- Difference between function arguments declared with & and * in C++
- C: How do I make a number always round up
- Is C++ Array passed by reference or by pointer?
- “cannot be used as a function error”
- Pause Console in C++ program
- Why the switch statement cannot be applied on strings?
- How to dynamically allocate arrays in C++
- ‘was not declared in this scope’ error
- Simple dictionary in C++
- Good input validation loop using cin – C++
- Are the C++ & and * operators inverses in all contexts?
- C++ for each, pulling from vector elements
- How do I erase an element from std::vector<> by index?
- What’s the C++ version of Java’s ArrayList
- Incomplete Type Is Not Allowed
- When to use extern in C++
- how to implement quick sort algorithm in C++
- C++ Vector of pointers
- What is uintptr_t data type
- const int = int const?
- Undefined reference to vtable
- In C++, what is a virtual base class?
- “Multiple definition of” C++ compiler error
- wntdll.pdb not loaded – Can’t see the exception
- Call a function from another file?
- C++: How to round a double to an int?
- Difference between const reference and normal parameter
- What does -> mean in C++?
- What’s the difference between char and char* in C++?
- How to pass optional arguments to a method in C++?
- How to copy a string of std::string type in C++?
- C++ forbids converting a `string` constant to `char*` – Alphabets to Morse converting program
- What is activation record in the context of C and C++?
- Static array vs. dynamic array in C++
- C++ terminate called after throwing an instance of ‘std::out_of_range’ Simple Averaging code
- C++ IDE with repl?
- error: use of deleted function
- Run C++ in command prompt – Windows
- pthread sleep linux
- 2D array vs array of arrays
- RPN Calculator for C++
- What does `Fatal Python error: PyThreadState_Get: no current thread` mean?
- Debug Assertion Failed: _CrtIsValidHeapPointer(block)
- gdb error not in executable format: File format not recognized
- C++ Erase vector element by value rather than by position?
- C++ Class ‘undeclared identifier”
- Destructor for Binary Search Tree
- What is the most popular general purpose C++ framework?
- Repeating a function in Python
- Adding message to assert
- c++ error: invalid types ‘int[int]’ for array subscript
- LINK : fatal error LNK1561: entry point must be defined ERROR IN VC++
- Trying to use int in getline
- What is the difference between an Abstract Data Type(ADT) and a Data Structure?
- What does the term “empty loop” refer to exactly in C and C++?
- c++ error c2015: too many characters in constant
- Splitting a C++ std::string using tokens, e.g. “;”
- Py_Initialize fails – unable to load the file system codec
- How to do std::string indexof in C++ that returns index of matching string?
- Parameter name omitted error?
- variable or field declared void
- Invalid conversion from ‘char’ to ‘const char *’
- How do I deal with “signed/unsigned mismatch” warnings (C4018)?
- Creating folders in C++
- heap corruption detected | C++
- Update g++ but still old version
- module unsafe for SAFESEH image C++
- Why are there two different getline() functions (if indeed there are)?