Error to use vector<int> in constructor?

Hi rooters,

 The following are the files, please notice the constructor in node.h (in fact, it is necessary to read node.h, test.C, and the root execution only, others being pasted here for completeness):

//-------------------node.h------------------
#ifndef NODE
#define NODE

#include “TObject.h”
#include

class node :public TObject
{
private:
vector vec;

public:
node(){}
node(vector a){}

ClassDef(node,0)
};

#endif

//-----------------node.cxx-------------------
#include “node.h”

ClassImp(node)

//--------------------nodeLinkDef.h--------------
#ifdef CINT
#pragma link C++ class node+;
#endif
//-------------------Makefile----------------------

ARCH = linux

filename =node

CXX =
ObjSuf = o
SrcSuf = cxx
ExeSuf =
DllSuf = so
OutPutOpt = -o

ROOTCFLAGS := $(shell root-config --cflags)
ROOTLIBS := $(shell root-config --libs)
ROOTGLIBS := $(shell root-config --glibs)

ifeq ($(ARCH),linux)

Linux with egcs, gcc 2.9x, gcc 3.x (>= RedHat 5.2)

CXX = /usr/bin/g++
CXXFLAGS = -O -Wall -fPIC
LD = /usr/bin/g++
LDFLAGS = -O
SOFLAGS = -shared
endif

ifeq ($(CXX),)
$(error $(ARCH) invalid architecture)
endif

INCLUDES = -I/home/luxg/source/include -I/hermes/pro/writeDST/ddl
CXXFLAGS += $(ROOTCFLAGS)
LIBS = $(ROOTLIBS) $(SYSLIBS) -L/home/luxg/source/lib
GLIBS = $(ROOTGLIBS) $(SYSLIBS)

#------------------------------------------------------------------------------

PARTICLEO = $(filename).$(ObjSuf) $(filename)Dict.$(ObjSuf)
PARTICLES = $(filename).$(SrcSuf) $(filename)Dict.$(SrcSuf)
PARTICLESO = lib$(filename).$(DllSuf)
PARTICLE = $(filename)$(ExeSuf)
PARTICLELIB = $(PARTICLESO)

OBJS = $(PARTICLEO)
PROGRAMS = $(PARTICLE)

#------------------------------------------------------------------------------

.SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf)
.PHONY: Aclock Hello Tetris

$(PARTICLESO): $(PARTICLEO)
$(LD) $(SOFLAGS) $(PARTICLEO) $(OutPutOpt) $(PARTICLESO)
@echo “$@ Successfully Made!!”

clean:
@rm -f $(OBJS) core

distclean: clean
@rm -f $(PROGRAMS) $(PARTICLESO) $(PARTICLELIB) Dict. *.def *.exp
*.root *.ps *.so .def so_locations
@rm -rf cxx_repository

.SUFFIXES: .$(SrcSuf)

$(filename).$(ObjSuf): $(filename).h

$(filename)Dict.$(SrcSuf): $(filename).h $(filename)LinkDef.h
@echo “Generating dictionary $@…”
@rootcint -f $@ -c $^

.$(SrcSuf).$(ObjSuf):
$(CXX) $(CXXFLAGS) -c $<

//******************* make **********************
$ make
/usr/bin/g++ -O -Wall -fPIC -pthread -I/home/luxg/root/root-4.04.02g/include -c node.cxx
Generating dictionary nodeDict.cxx…
/usr/bin/g++ -O -Wall -fPIC -pthread -I/home/luxg/root/root-4.04.02g/include -c nodeDict.cxx
/usr/bin/g++ -shared node.o nodeDict.o -o libnode.so
libnode.so Successfully Made!!

//-------------------------test.C---------------------
#includelibnode.so
#include

test()
{

vector vec;
vec.push_back(23);

}

//******************root **********************
$ root
root [0] .x test.C
Error: Can’t call vector<int,allocator >::push_back(23) in current scope FILE:test.C LINE:8
Possible candidates are…
filename line:size busy function type and name (in vector<int,allocator >)
Error: Symbol vec is not defined in current scope FILE:test.C LINE:8
Error: Failed to evaluate vec.push_back(23)Possible candidates are…
filename line:size busy function type and name
*** Interpreter error recovered ***
root [1] .x test.C
Warning: template pair duplicate definition FILE:/home/luxg/root/root-4.04.02g/cint/stl/_pair.h LINE:21
Warning: template vector duplicate definition FILE:/home/luxg/root/root-4.04.02g/cint/stl/_vector.h LINE:35
Error: Can’t call vector<int,allocator >::push_back(23) in current scope FILE:test.C LINE:9
Possible candidates are…
filename line:size busy function type and name (in vector<int,allocator >)
Error: Symbol vec is not defined in current scope FILE:test.C LINE:9
Error: Failed to evaluate vec.push_back(23)Possible candidates are…
filename line:size busy function type and name
*** Interpreter error recovered ***
root [2]

Can you tell me where the problems are? 

Cheers, Xian-Guo Lu

Can you tell me where the problems are?

You probably did not build the ‘cintdlls’:
cd $ROOTSYS
gmake cintdlls

alternatively you can use
#pragma link C++ class vector;

Cheers,
Philippe.

Hi Philippe,
:laughing: Thank you very much!

It is that I did not add the following code to the nodeLinkDef.h:

#pragma link C++ class vector+;

And now things go smoothly.

And the previous problem is that after I had loaded the library, and when I called "vector vec; " , it did not work. The situation is shown as above.

Again, thank you very much!