Error : Illegal initialization of v. Constructor exists


hi, my simple code ran in ROOT 6.22 without any problem but it shows an error in ROOT 5.34 which I must work with. Does someone have any idea to fix the error?

void t(){
    vector<int> v={1,2,3};
    cout << v[0] << endl;
}

root [3] .x t.C
Warning: template pair duplicate definition /usr/local/lib/root/cint/cint/stl/_pair.h:31:
Warning: template reverse_iterator duplicate definition /usr/local/lib/root/cint/cint/stl/_iterator.h:269:
Warning: template vector duplicate definition /usr/local/lib/root/cint/cint/stl/_vector.h:44:
Error: Illegal initialization of v. Constructor exists  t.C:4:
*** Interpreter error recovered ***
root [4] 

ROOT Version: 5.34
Platform: Not Provided
Compiler: Not Provided


5.34 does not support this construct. In 5.34 the C++ interpretation was done by CINT, a C interpreter which was very incomplete.
With 5.34 try to use ACLIC:

root [0] .x t.C++

ACLIC also returns the same error. how can I change it to fix? I should note that I want the g variable to be a vector.
thanks

The following works for me when I use ACLIC with ROOT 6:

void t(){
    vector<int> v={1,2,3};
    printf("%d\n",v[0]);
}

ACLIC should be the same with ROOT 5 and ROOT 6.

% root t.C++
   ------------------------------------------------------------------
  | Welcome to ROOT 6.23/01                        https://root.cern |
  | (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosx64 on Aug 31 2020, 07:45:56                      |
  | From heads/master@v6-23-01-1119-gc464388358                      |
  | With Apple clang version 11.0.3 (clang-1103.0.32.62)             |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] 
Processing t.C++...
Info in <TMacOSXSystem::ACLiC>: creating shared library /Users/couet/Downloads/./t_C.so
1

ACLIC also returns the same error. how can I change it to fix?

Hide the non-C++98 code from CINT:

#ifdef __CINT__
void t();
#else
void t(){
    vector<int> v={1,2,3};
    cout << v[0] << endl;
}
#endif

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.