Strange problem when inheriting from std::fstream


First off, I’m brand new to ROOT, so apologies if this problem is a waste of someone’s time.

Long story short, I was trying to add a source file into root, and it crashed with a stack trace whenever I tried to use it. I wasn’t terribly surprised, since I didn’t quite yet know what I was doing, so I decided to try a very simple example. Here is said example:


using namespace std;

class testclass : public fstream {
int i;

int main() {
testclass test;“C:\test.txt”, fstream::in);
string str;
getline(test, str);
cout << str << endl;

This code, when loaded into root, produces the same problem; I get a stack trace from ROOT, see the wonderful “root.exe has encountered a problem and needs to close” error from Windows, and that’s it. Thinking maybe this was a windows thing, I got on my linux computer and did the same thing, with no luck. Luckily, however, it gave me more information; the terrible error is a Segmentation fault.

Here is what I saw for the whole ROOT session in the command line:

Compiled on 14 December 2006 for win32.

CINT/ROOT C/C++ Interpreter version 5.16.16, November 24, 2006
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] .x setup_env.C
root [1] .L Testfile.cpp
root [2] main()

=============== STACKTRACE ===============

================ Thread 0 ================

================ Thread 1 ================

================ Thread 2 ================

================ Thread 3 ================

============= END STACKTRACE =============

(The setup env is just a script with a gROOT->SetMacroPath() to point to a temporary folder where my testing stuff is located…I didn’t want to put that in the logon script since I don’t use it very often)

Thinking maybe I was somehow being an idiot with this, I compiled the little program externally, and it worked just fine.

Clearly, I’m missing something, but I’m not completely sure what :confused: .

Your help is highly appreciated!


This due to the fact that compiled code does not handle well ‘interpreted’ class inheriting from compiled class. To solve you problem simply compile your script (by using ACLiC).


Well, at the moment, I’m now fighting ACLiC’s dislike of spaces in the filenames for the compiler. Unfortunately, my Visual C++ compiler is in a directory that has spaces along the way, so if I do .L +, it chokes on the spaces.

I’ll fool around with it a bit longer before I post anymore on it. Thank you for pointing me in the right direction!