Thread: error: expected constructor, destructor, or type conversion before ‘(’

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    2

    Question error: expected constructor, destructor, or type conversion before ‘(’

    Hi. I'm new to c++ programming and currently I'm trying to write a code in Geant4 toolkit. Basically, I have this class that gives one error when compiling.

    RunAction.cc:
    Code:
    #include "RunAction.hh"
    #include "Run.hh"
    #include "GeometriaConstruction.hh"
    #include "PrimaryGeneratorAction.hh"
    #include "HistoManager.hh"
    
    #include "G4Run.hh"
    #include "G4RunManager.hh"
    #include "G4UnitsTable.hh"
    #include "G4SystemOfUnits.hh"
    
    #include "Randomize.hh"
    #include <iomanip>
    
    //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
    
    RunAction::RunAction (DetectorConstruction* det, PrimaryGeneratorAction* prim)
      : G4UserRunAction(),
        fDetector(det), fPrimary(prim), fRun(0), fHistoManager(0)
    {
     // Book predefined histograms
     fHistoManager = new HistoManager(); 
    }
    
    //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
    
    RunAction::~RunAction()
    {
     delete fHistoManager;
    }
    
    //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
    
    G4Run* RunAction::GenerateRun()
    { 
      fRun = new Run(fDetector); 
      return fRun;
    }
    
    //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
    
    void RunAction::BeginOfRunAction(const G4Run*)
    {    
      // save Rndm status
      G4RunManager::GetRunManager()->SetRandomNumberStore(false);
      if (isMaster) G4Random::showEngineStatus();
      
      // keep run condition
      if (fPrimary) { 
        G4ParticleDefinition* particle 
          = fPrimary->GetParticleGun()->GetParticleDefinition();
        G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();
        fRun->SetPrimary(particle, energy);
      }
                 
      //histograms
      //
      G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
      if ( analysisManager->IsActive() ) {
        analysisManager->OpenFile();
      }  
    }
    
    //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
    
    void RunAction::EndOfRunAction(const G4Run*)
    {
      if (isMaster) fRun->EndOfRun();    
      
      //save histograms      
      G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
      if ( analysisManager->IsActive() ) {
        analysisManager->Write();
        analysisManager->CloseFile();
      }
          
      // show Rndm status
      if (isMaster) G4Random::showEngineStatus();
    }
    RunAction.hh:
    Code:
    #ifndef RunAction_h
    #define RunAction_h 1
    
    #include "G4UserRunAction.hh"
    #include "globals.hh"
    
    //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
    
    class GeometriaConstruction;
    class Run;
    class PrimaryGeneratorAction;
    class HistoManager;
    
    //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
    
    class RunAction : public G4UserRunAction
    {
      public:
        RunAction(GeometriaConstruction*, PrimaryGeneratorAction*);
       ~RunAction();
    
      public:
        virtual G4Run* GenerateRun();  
        virtual void BeginOfRunAction(const G4Run*);
        virtual void   EndOfRunAction(const G4Run*);
                                
      private:
        GeometriaConstruction*      fDetector;
        PrimaryGeneratorAction*    fPrimary;
        Run*                       fRun;    
        HistoManager*              fHistoManager;
            
    };
    
    //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
    
    #endif
    The following error when trying to compile is:
    Code:
    geo@george-Ubuntu:~/Desktop/teste$ make
    Scanning dependencies of target ribras
    [  6%] Building CXX object CMakeFiles/ribras.dir/src/RunAction.cc.o
    /home/geo/Desktop/from the scratch/src/RunAction.cc:18:22: error: expected constructor, destructor, or type conversion before ‘(’ token
     RunAction::RunAction (DetectorConstruction* det, PrimaryGeneratorAction* prim)
                          ^
    make[2]: *** [CMakeFiles/ribras.dir/src/RunAction.cc.o] Error 1
    make[1]: *** [CMakeFiles/ribras.dir/all] Error 2
    make: *** [all] Error 2

    Anyone got an Idea of how Can I fix it? I've tried searching on stackexchange and ther sites but couldn't come up with a solution.
    If needed I can try uploading other files I've written.

    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I notice that in your RunAction class definition, you wrote:
    Code:
    RunAction(GeometriaConstruction*, PrimaryGeneratorAction*);
    But when defining the constructor, you wrote:
    Code:
    RunAction::RunAction (DetectorConstruction* det, PrimaryGeneratorAction* prim)
    Why GeometriaConstruction in one case and DetectorConstruction in the other? My guess is that DetectorConstruction was not declared at this point, and rather you should have written:
    Code:
    RunAction::RunAction(GeometriaConstruction* det, PrimaryGeneratorAction* prim)
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2015
    Posts
    2
    Quote Originally Posted by laserlight View Post
    I notice that in your RunAction class definition, you wrote:
    Code:
    RunAction(GeometriaConstruction*, PrimaryGeneratorAction*);
    But when defining the constructor, you wrote:
    Code:
    RunAction::RunAction (DetectorConstruction* det, PrimaryGeneratorAction* prim)
    Why GeometriaConstruction in one case and DetectorConstruction in the other? My guess is that DetectorConstruction was not declared at this point, and rather you should have written:
    Code:
    RunAction::RunAction(GeometriaConstruction* det, PrimaryGeneratorAction* prim)
    jesus christ, i've been looking at this for hours. In my head, detector and geometria is the same, that's why I havent found the error.

    Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-18-2013, 01:50 PM
  2. Replies: 3
    Last Post: 06-05-2012, 01:14 PM
  3. Replies: 1
    Last Post: 04-15-2011, 02:47 PM
  4. Expected constructor, destructor, type conversion
    By SterlingM in forum C++ Programming
    Replies: 6
    Last Post: 03-26-2010, 01:16 PM
  5. expected constructor, destructor, or type conversion before '('
    By cosmiccomputing in forum C Programming
    Replies: 5
    Last Post: 06-16-2008, 11:03 PM