Q:

First defined here error after inclusion of .cpp-file

I have the following two c++ files: 
somNode.cpp:
#include <random>
#include <iostream>
#include <chrono>

/*
* This class represent a node in the som-grid
*/
class somNode
{
    private:
        // Weight of the node representing the color
        int nodeWeights[3];
        // Position in the grid
        double X, Y;
        // corner coorinates for drawing the node on the grid
        int top_Left, top_Right, bottom_Left, bottom_Right;

    public:
        // Constructor
        somNode(int tL, int tR, int bL, int bR)
        {
            top_Left = tL;
            top_Right = tR;
            bottom_Left = bL;
            bottom_Right = bR;
        }

};

void my_custom_function(int nodeWeights[])
{
  // construct a trivial random generator engine from a time-based seed:
  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
  std::default_random_engine generator (seed);
  std::uniform_int_distribution<int> distribution(0,255);
  for(int i=0; i<3; i++)
  {
    nodeWeights[i] = distribution(generator);
  }
}

and main.cpp: 
#include <iostream>
#include <ctime>
#include <cstdlib>

#include "somNode.cpp"

using namespace std;

int main ()
{
    return 0;
}

If I try to run this code I get: 

Why do I get this error? I don't understand why the compiler complains about the inclusion? I'm a beginner in C++ programming and everything is a bit new to me x) I know I should use header files in inclusions but I'm just trying to experiment and learn the language :) 

A:

Don't #include "someNode.cpp" from within a source file.
Your compiler is producing more than one copy of my_custom_function, and the linker doesn't know which one to pick.
Use a header file instead which contains function prototypes and class declarations, and #include that if necessary.

