I have two classes, class A and class B. Class B has class A as a member. I’ve been having an issue when trying to compile class B using the following in root .L classB.cxx+
I get an error message about undefined references to methods of class A. What am I missing? I have included the proper headers, but I still have an issue. Below is a simple example of the issue and the resulting error.
Here is the code classA.h
[code]#ifndef CLASSA_H
#define CLASSA_H
#include “TROOT.h”
class A
{
private:
Float_t fX;
public:
A(Float_t x);
Float_t GetX();
ClassDef(A,1)
};
#endif[/code]
classA.cxx:
#include "classA.h"
ClassImp(A)
A::A (Float_t x)
{
fX = x;
}
Float_t A::GetX)
{
return fX;
}
classB.h:
[code]#ifndef CLASSB_H
#define CLASSB_H
#include “TROOT.h”
#include “classA.h”
class B
{
private:
Float_t fY;
A *fA;
public:
B(Float_t y);
Float_t GetY();
ClassDef(B,1)
};
#endif[/code]
classB.cxx:
[code]#include “classB.h”
#include “classA.h”
B::B(Float_t y)
{
fY = y;
fA = new A(fY);
}
Float_t B::GetY()
{
return fA->GetX();
}
[/code]
I can compile classA with no issues.
To compile classB I use .L classB.cxx+
I then get an error message about classA /research/S323/DAQsvn/beta-n_analysis/trunk/source/errorExample/classB_cxx_ACLiC_dict.o: In function `B::B(float)':
classB_cxx_ACLiC_dict.cxx:(.text+0x114a): undefined reference to `A::A(float)'
/research/S323/DAQsvn/beta-n_analysis/trunk/source/errorExample/classB_cxx_ACLiC_dict.o: In function `B::GetY()':
classB_cxx_ACLiC_dict.cxx:(.text+0x1285): undefined reference to `A::GetX()'
collect2: ld returned 1 exit status
Error in <ACLiC>: Compilation failed!