Hello,
I know how to add a class to root using ACliC. For example, if I have a
class called c1 in the file c1.cpp, I use
.L c1.cpp++
Then I can use the class (e.g c1 myc creates a c1 object) Everything is
fine...
If I make a new class called c2 that has, as a member, an object of type c1,
I can't get it to work - when I try to instantiate c2 it fails (see output
session below)
Furthermore, when I use the cint command .file, it shows an asterisk next to
the file that has c2.
My question is: How do I implement composition within root? I include my
simple classes c1 and c2 at the bottom:
Thanks!
Ed Oltman
C:\rootbug>root
the current keyboard layout is 437
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 3.02/07 10 January 2002 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
Compiled for win32.
CINT/ROOT C/C++ Interpreter version 5.15.25, Jan 6 2002
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] .L c1.cpp++
Info in <ACLiC>: creating shared library C:\rootbug\c1_cpp.dll
83.cxx
117.cxx
121.cxx
123.cxx
s19g.cpp
Creating library c1_cpp.lib and object c1_cpp.exp
root [1] .L c2.cpp++
Info in <ACLiC>: creating shared library C:\rootbug\c2_cpp.dll
83.cxx
117.cxx
121.cxx
123.cxx
s19g.4.cpp
Creating library c2_cpp.lib and object c2_cpp.exp
root [2] c2 myc
Error: Symbol c2myc is not defined in current scope
FILE:C:\DOCUME~1\eoltman\LOCALS~1\Temp\83 LINE:1
*** Interpreter error recovered ***
root [3]
------------------------- Here is c1 --------------------
c1.h:
#ifndef _C1_H_
#define _C1_H_
#include "TObject.h"
class c1 : public TObject
{
public:
c1();
void doit();
#if !defined(__CINT__) || defined(__MAKECINT__)
ClassDef(c1,1)
#endif
};
#endif
c1.cpp:
#include <iostream.h>
#include "c1.h"
#if !defined(__CINT__) || defined(__MAKECINT__)
ClassImp(c1)
#endif
c1::c1()
{
cout<<"c1 constructor called"<<endl;
}
void c1::doit()
{
cout<<"this is c1::doit"<<endl;
}
------------------------- Here is c2 --------------------
c2.h:
#ifndef _C2_H_
#define _C2_H_
#include "TObject.h"
#include "c1.h"
class c2 : public TObject
{
public:
c2();
void doit();
private:
c1 *m_c1;
#if !defined(__CINT__) || defined(__MAKECINT__)
ClassDef(c2,1)
#endif
};
#endif
c2.cpp:
#include <iostream.h>
#include "c2.h"
#if !defined(__CINT__) || defined(__MAKECINT__)
ClassImp(c2)
#endif
c2::c2()
{
m_c1 = 0;
}
void c2::doit()
{
m_c1 = new c1;
m_c1->doit();
}
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:40 MET