Dear C++ users,
My name is Kim, and I am fairly new to C++ programing. I have worked with it, but I have little knowledge of the language itself. I recently tried to compile this and end up with an error that follows
1 2 3 4 5 6 7 8
<**Compiling**> RFSensor.cxx
g++ -Wall -fPIC -pthread -m64 -I/usr/local/root-pro/include -I/sw/include -c RFSensor.cxx -o RFSensor.o
RFSensor.cxx:31: error: prototype for `Bool_t RFSensor::testTrigger(RFPulse)' does not match any in class `RFSensor'
RFSensor.h:23: error: candidate is: Bool_t RFSensor::testTrigger(RFPulse&)
RFSensor.cxx: In member function `Bool_t RFSensor::testTrigger(RFPulse)':
RFSensor.cxx:31: error: `<anonymous>' has incomplete type
RFSensor.h:15: error: forward declaration of `struct RFPulse'
make: *** [RFSensor.o] Error 1
Could someone please highlight the error involved. My initial thoughts is that either RFSensor or RFPulse is not defined as a class. The following is the header for RFSensor.
1 2 3 4 5 6 7 8 9 10 11
class RFPulse;
class RFSensor : public TObject {
public:
RFSensor();
RFSensor(TVector3 relPos);
~RFSensor();
Bool_t testTrigger(RFPulse &pulsey);
TVector3 getRelPos() {return fRelPos;}
Am I right that I need to define RFPulse? Or is there more errors that I've yet to pick up on. Thank you in advance,
yes in headers it is best practice to define params, otherwise clients/other programmers using the header has no idea what some_function(int,int,string,string,double,char) means.... Usually the variable name gives a bit more meaning to it.
as for why this error is occurring I cannot elaborate unfortunately.
The code you pasted above looks fine. You've forward declared RFPulse because the header does not need
to know anything about the type (at least the part that you pasted), so I would agree with the forward
declaration.
Just looking at your error messages, I think you have one, maybe two problems.
First, In RFSensor.cxx you are going to need to #include the header file that actually declares RFPulse. You
haven't done that, so the only declaration the compiler sees while compiling RFSensor.cxx is the incomplete
(forward) declaration in RFSensor.h.
Second, because testTrigger takes an RFPulse by non-const reference, you cannot pass a temporary RFPulse
instance to that function. I don't think you are doing that, because if you were, I'd expect you to get
an error message about binding temporaries to non-const references. However, depending upon your
compiler, I could see getting the error message you are getting (lines 3-4)... if you were passing a temporary,
the compiler would want to match a function that took an RFPulse by value to compile.
If you are unable to fix all the compile errors, you'll have to post the part of the .cxx file that is causing the
compile errors.
Firstly thank you to you two for replying and identifying the cause, I've included the RFPulse.h in the RFSensor.cxx. It now points to a new error of which I have no understanding
<**Compiling**> RFSensor.cxx
g++ -Wall -fPIC -pthread -m64 -I/usr/local/root-pro/include -I/sw/include -c RFSensor.cxx -o RFSensor.o
In file included from RFSensor.cxx:7:
RFPulse.h: In member function `TVector3 RFPulse::getRelPos()':
RFPulse.h:22: error: `fRelPos' was not declared in this scope
RFPulse.h:22: warning: unused variable 'fRelPos'
RFSensor.cxx: At global scope:
RFSensor.cxx:31: error: prototype for `Bool_t RFSensor::testTrigger(RFPulse)' does not match any in class `RFSensor'
RFSensor.h:34: error: candidate is: Bool_t RFSensor::testTrigger(RFPulse&)
make: *** [RFSensor.o] Error 1
#ifndef RFPULSE_H
#define RFPULSE_H
#include "TObject.h"
#include "TClonesArray.h"
#include "TVector3.h"
class RFPulse : public TObject {
public:
RFPulse();
RFPulse(TVector3 relPos);
~RFPulse();
TVector3 getRelPos() {return fRelPos;}
private:
TVector3 fLocation;
TVector3 fDirection;
//Need something that describes the frequency and phase content here
//Will probably just be a couple of arrays.
ClassDef(RFPulse,1);
};
#endif //RFPULSE_H
Where line 22 has the fRelPos. I am unsure of what the error means, can someone inform me of the cause? Thank you
If it is needed this is the source for RFSensor.cxx