#pragma problems for function: ostream &operator

From: Maurik Holtrop (maurik.holtrop@unh.edu)
Date: Tue May 25 1999 - 16:48:24 MEST


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

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





This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:33 MET