943,786 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 547
  • C++ RSS
Jul 6th, 2009
0

Re: Random number generator's

Expand Post »
Hi,

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?

C++ Syntax (Toggle Plain Text)
  1. #ifndef MULTIFILE_PROJECT
  2. // If compiled as a single file then include these cpp files,
  3. // If compiled as a project then compile and link in these cpp files.
  4. // Include code for the chosen random number generator:
  5. #include "mersenne.cpp"
  6. // define system specific user interface:
  7. #include "userintf.cpp"
  8. #endif
  9.  
  10.  
  11. #include <time.h> // define time()
  12. #include "randomc.h"

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

Quote ...
GABaseSolver.obj : error LNK2005: "private: void __thiscall CRandomMersenne::Init0(int)" (?Init0@CRandomMersenne@@AAEXH@Z) already defined in GA1DArraySolution.obj
Please help.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
somyasinha is offline Offline
1 posts
since May 2009
Jul 6th, 2009
0

Re: Random number generators

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
c++ Syntax (Toggle Plain Text)
  1. #ifndef RANDOMC_H
  2. #define RANDOMC_H
  3. // all the code in randomc.h goes here
  4. #endif
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.
Reputation Points: 215
Solved Threads: 186
Veteran Poster
NathanOliver is offline Offline
1,066 posts
since Apr 2009
Jul 6th, 2009
0

Re: Random number generators

Some compilers that are stupid the gaurds still wont work, if that is so try using pragma once at the top.
C++ Syntax (Toggle Plain Text)
  1. #pragma once
Last edited by u8sand; Jul 6th, 2009 at 8:44 pm.
Reputation Points: 78
Solved Threads: 15
Junior Poster
u8sand is offline Offline
131 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Need help initializing variables
Next Thread in C++ Forum Timeline: Checking if variable is a number or a letter: Error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC