Function already defined error in C++

By default, these functions have external linkage. That means each translation unit has functions called double round(double r) and float round(float r), which causes a name collision at link time.

Some possible solutions are:

  1. Declare the functions as static, which implies internal linkage
  2. Inline the functions
  3. Move the implementation out of the header and into a c/c++ file

Read more here:
What is external linkage and internal linkage?

By the way, include guards protect a single translation unit from including a header file multiple times. That’s a different issue that what you’re seeing here.

Leave a Comment