How do I use the generator in the file? I keep randomc.h as a header file in the Visual c++ project. My project has several header files and several .cpp files, many of which require to use the random no. generator. I have copied all the files in the zip folder into the folder for my project files.
Do I write this in each file that uses the generator?

// If compiled as a single file then include these cpp files, 
// If compiled as a project then compile and link in these cpp files.
   // Include code for the chosen random number generator:
   #include "mersenne.cpp"
   // define system specific user interface:
   #include "userintf.cpp"

#include <time.h>                      // define time()
#include "randomc.h"

The compling is ok. But I get a lot of linking errors, e.g.,

GABaseSolver.obj : error LNK2005: "private: void __thiscall CRandomMersenne::Init0(int)" (?Init0@CRandomMersenne@@AAEXH@Z) already defined in GA1DArraySolution.obj

Please help.

8 Years
Discussion Span
Last Post by u8sand

in every header file it is a good idea to use inclusion guards. so to stop it from getting defined all the time just put

#ifndef RANDOMC_H
#define RANDOMC_H
//  all the code in randomc.h goes here

this will make sure that the file is only included the first time and every other time #include "randomc.h" is encountered the compiler will skip that file because it is already defined. I've found this makes things easier down the road and saves some debugging time.


Some compilers that are stupid the gaurds still wont work, if that is so try using pragma once at the top.

#pragma once
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.