RE: private members

From: Philippe Canal <>
Date: Fri, 21 Jan 2005 09:03:49 -0600


Within a ROOT dictionary, we had to bend the rule a little bit in order to properly implemented the I/O (the I/O itself has to sligthly break the data incapsulation since it needs to modify directly the data members). Since the file compiled by ACLiC are included within their dictionary, this leads to the behavior you have observed.


-----Original Message-----
From: [] On Behalf Of
Sent: Friday, January 21, 2005 6:43 AM
Subject: [ROOT] private members

Dear all

I found that it is possible to manipulate class private data members outside the class within ROOT compiled code. See bellow the shortest code reproducing the problem.

/**************** class definition *********/

#ifndef A_h
#define A_h

class A {
             A() { i = 0; }
           ~A() { }
         int i;


/************* function definition **********/

void testFunc()

    A a;
    a.i = 5;
    std::cout<<"a.i = "<<a.i<<std::endl; }

I compile both the class and the function and execute the function.

root [0] .L A.h++
Info in <TUnixSystem::ACLiC>: creating shared library /cern/ROOT/root401/mylib//home/simonyan/ROOT/leakage/classes/ root [1] .L testFunc.cpp++
Info in <TUnixSystem::ACLiC>: creating shared library /cern/ROOT/root401/mylib//home/simonyan/ROOT/leakage/functions/testFunc_cpp. so
root [2]
root [2] testFunc()
a.i = 5

Of course it is impossible to compile testFunc.cpp with g++ because A::i is private member.
Usually people ask why something does not work, but this is not the case. I would like to know why and how this code works ? It violates data incapsulation, which is one of the main principle of Object-Oriented programming.


        Margar Simonyan Received on Fri Jan 21 2005 - 16:05:27 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:04 MET