#pragma problems for function: ostream &operator

Maurik Holtrop (maurik.holtrop@unh.edu)
Tue, 25 May 1999 14:48:24 +0000


This is a multi-part message in MIME format.
--------------38CE1536056467FF75149EB2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Dear Root,

I have a little example code that works great when interpreted, but when
compiled does not function properly. I suspect an incorrect LinkDef.h file.
I tried a whole slew of different #pragma link C++ function combinations
without much results. Could someone please help me find a way to get access
to the ostream &operator<<() functions?

Maurik

--------------------------------------------------------------------------------

Interpreted output: (Note: to make the interpreter work properly I comment
out the ClassDef and ClassImp)

root [0] .L test2.cc
root [1] tempa aaa(1,1.234);
root [2] cout << aaa;
Int: 1 Float: 1.234 C: Initialized with constructor.

Compiled output:

server|root>g++ -c -DEGCS -fno-rtti -O -Wall -fPIC -DLinux -DRedHat5
-I/usr/local/root/include test2.cc
server|root>rootcint -f test2cint.cc -c test2.h test2_LinkDef.h
Note: operator new() masked 1c
Note: operator delete() masked 1c
server|root>g++ -c -DEGCS -fno-rtti -O -Wall -fPIC -DLinux -DRedHat5
-I/usr/local/root/include test2cint.cc
server|root>g++ -shared test2.o test2cint.o -o test2.so
server|root>
server|root>
server|root>root
CINT/ROOT C/C++ Interpreter version 5.13.83, Dec 2 1998
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] .L test2.so
root [1] tempa aaa(1,1.234);
root [2] cout << aaa;
Error: No symbol cout in current scope FILE:/tmp/09439baa LINE:1
(class tempa)139247968
*** Interpreter error recovered ***
root [3]

---------------Code: test2.h -------------------
#ifndef __CINT__
#include "TObject.h"
#endif

#include <iostream.h>

class tempa : public TObject{

public:
int i;
float x;
char str[256];

public:

tempa(){};
~tempa(){};
tempa(int a,float b){
i=a;
x=b;
strcpy(str,"Initialized with constructor.");
}

void Print(){
cout << (*this) << endl;
}

friend ostream &operator<<(ostream &os,tempa &b);

ClassDef(tempa,1)
};

---------------- Code: test2.cc ------------------------
#include "test2.h"

ClassImp(tempa)

ostream &operator<<(ostream &os,tempa &b)
{
os << "Int: " << b.i;
os << " Float: " << b.x;
os << " C: " << b.str << endl;
return(os);
}
--------------- Code: test2LinkDef.h ---------------------
#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class tempa;
#pragma link C++ function operator<<(ostream &, class tempa &);
#endif

--------------------------------------------------

--------------38CE1536056467FF75149EB2
Content-Type: text/x-vcard; charset=us-ascii;
name="maurik.holtrop.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Maurik Holtrop
Content-Disposition: attachment;
filename="maurik.holtrop.vcf"

begin:vcard
n:Holtrop;Maurik
tel;fax:(603) 862-2998
tel;home:(603) 659-8765
tel;work:(603) 862-2019
x-mozilla-html:FALSE
url:http://www.physics.unh.edu/Maurik
org:UNH Nuclear Physics
adr:;;9 Library Way;Lee;NH;03824;USA
version:2.1
email;internet:maurik.holtrop@unh.edu
x-mozilla-cpt:;1216
fn:Maurik Holtrop
end:vcard

--------------38CE1536056467FF75149EB2--