Message: Re: Compilation Problem - Using Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Note Re: Compilation Problem - Using  

Forum: Installation and Configuration
Re: Question Compilation Problem - Using "Phase Space" File as Input For Simulation (Ben Hug)
Date: 30 Jan, 2012
From: Ben Morgan <Ben Morgan>

Hi Ben,

On Sat, 28 Jan 2012 03:29:37 GMT, Ben Hug wrote:
> I have included the following: #include  using namespace std;

One hint here - try to avoid using namespace std;, for the reasons outlined in the C++ FAQ (Especially as you already qualify your types by std::).

> ### FOLLOWING IS IN CONSTRUCTOR### std::ifstream ifs;
> ifs.open("My_File.binary"); if(ifs.is_open()){G4cout<<######< else {G4cout<<####< 
> ###FOLLOWING IS IN DESTRUCTOR#### ifs.close();
> 
> ## FOLLOWING IS IN GENERATE PRIMARIES#### G4float all_data[8];
> ifs.read((char*)&all_data,size of all_data); DEFINE DATA HERE...
> 
> The compilation errors which keep popping up refer to the the lines
> #ifs.close() and ifs.read..... The error which is produced when
> compiling is error: ifs was not declared in this scope. If I comment out
> these line in the destructor the code compiles.

It looks like ifs is not a data member of your PrimaryGeneratorAction class - you declare it in the constructor, but unless it's a data member, it'll go out of scope once the constructor exits, so won't be seen by other methods. If that's the case, just add it as a data member and it should be fine. If you do already have it as a data member, we'll need to see the all header and source file to do a more in depth diagnosis.

> I have done a little bit of reading and I am compiling using gcc. forums
> suggest that using g++ can solve this issue but as far as Im aware I
> thought that G4 required Gcc...

"GCC" is the GNU Compiler Collection, which supplies the gcc C compiler, and the g++ C++ compiler. Geant4 is C++ so requires g++ in this case!

Cheers,

Ben.

 Add Message Add Message
to: "Re: Compilation Problem - Using "

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]