Hi Mark, the member SinnerClass junk is private. You cannot write a C++ statement like test2->junk.Print(). You should provide a member function returning a reference to the member junk, or declare your members public. Rene Brun On Wed, 8 Oct 2003, Mark Wallace wrote: > Hello, > I'm new to ROOT and I'm having problems in reading the tree I > created and it looks like I am having problems with seeing a class that > is inside another class. Here is an example program I was playing with > to test this. > > File SClass.h > -------------------------------------------------------------------------------------------- > #include <iostream> > #include "TObject.h" > using namespace std; > > class SInnerClass : public TObject { > private: > Float_t fXX; > Float_t fYY; > public: > SInnerClass() {fXX = fYY = -2;} > void Print() const; > ClassDef (SInnerClass,1) > }; > class SClass : public TObject { > private: > Float_t fX; > Float_t fY; > SInnerClass junk; > public: > SClass() {fX = fY = -1;} > void Print() const; > ClassDef (SClass,1) > }; > ------------------------------------------------------------------------------------------------- > File SClass.cpp > ------------------------------------------------------------------------------------------------- > #include "SClass.h" > ClassImp (SClass); > ClassImp (SInnerClass); > > void SClass::Print() const { > cout << "fX = " << fX << ", fY = " << fY << endl; > }; > void SInnerClass::Print() const { > cout << "fXX = " << fXX << ", fYY = " << fYY << endl; > }; > ------------------------------------------------------------------------------------------------ > File LinkDef.h > ------------------------------------------------------------------------------------------------ > #ifdef __CINT__ > #pragma link off all globals; > #pragma link off all classes; > #pragma link off all functions; > #pragma link C++ class SInnerClass+; > #pragma link C++ class SClass+; > ------------------------------------------------------------------------------------------------ > I compile this to give me a shared library and run this in root using > this makefile > ------------------------------------------------------------------------------------------------- > ARCH = linuxdeb > CXX = > ObjSuf = o > SrcSuf = cxx > ExeSuf = > DllSuf = so > OutPutOpt = -o > ROOTCFLAGS := $(shell root-config --cflags) > ROOTLIBS := $(shell root-config --libs) > ROOTGLIBS := $(shell root-config --glibs) > CXX = g++ > CXXFLAGS = -O -Wall -fPIC > LD = g++ > LDFLAGS = -O > SOFLAGS = -shared > CXXFLAGS += $(ROOTCFLAGS) > LIBS = $(ROOTLIBS) $(SYSLIBS) > GLIBS = $(ROOTGLIBS) $(SYSLIBS) > > SCLASSO = SClass.$(ObjSuf) SClassDict.$(ObjSuf) > SCLASSS = SClass.$(SrcSuf) SClassDict.$(SrcSuf) > SCLASSSO = libSClass.$(DllSuf) > SCLASS = SClass$(ExeSuf) > SCLASSLIB = $(SCLASSSO) > OBJS = $(SCLASSO) > PROGRAMS = $(SCLASS) > > .SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf) > $(SCLASSSO): $(SCLASSO) > $(LD) $(SOFLAGS) $(LDFLAGS) $^ $(OutPutOpt) $@ > @echo "$@ done" > > SClassDict.$(SrcSuf): SClass.h LinkDef.h > @echo "Generation dictonary $@..." > @rootcint -f $@ -c $^ > .$(SrcSuf).$(ObjSuf): > $(CXX) $(CXXFLAGS) -c $< > --------------------------------------------------------------------------------------------- > In root I type this > > root [0] .L libSClass.so > root [1] SClass *test2 = new SClass; > root [2] test2->Print(); > fX = -1, fY = -1 > root [3] test2->junk.Print(); > Error: Symbol test2 is not defined in current scope FILE:(tmpfile) LINE:1 > Error: Failed to evaluate test2->junkError: Failed to evaluate > test2->junk.Print()Possible candidates are... > filename line:size busy function type and name > *** Interpreter error recovered *** > > How do you define a class inside a class so you can use it in root? > > I'm using Root Version 3.05/04 running on debian linux > > Thanks > > Mark > >
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:16 MET