Creating dictionary for class containing vector<InnerClas

Hi,

I am trying to generate a dictionary for a class which defines two inner classes, and contains std::vector as a member:

#ifndef MYCLASS_H
#define MYCLASS_h

#include <iostream>
#include <vector>

using namespace std;

class MyClass
{
public:
  // class MyInnerOne
  class MyInnerOne
  {
  public:
    MyInnerOne();
    virtual ~MyInnerOne();
    void print();
  private:
    double member_;
  };

  // class MyInnerTwo
  class MyInnerTwo
  {
  public:
    MyInnerTwo();
    virtual ~MyInnerTwo();
    void print();
  private:
    double member_;
  };
  
  
  MyClass();
  MyClass(const MyInnerOne& one, const std::vector<MyInnerTwo>& twos)
    : one_(one), twos_(twos) {}
  virtual ~MyClass();
  void print();
private:
  double     member_;
  MyInnerOne one_;
  std::vector<MyInnerTwo> twos_;
};

#endif

I use the following Makefile:

CXX          = g++

ROOTCXXFLAGS = $(shell $(ROOTSYS)/bin/root-config --cflags)
CXXFLAGS     = -O3 -Wall -fPIC -I. $(ROOTCXXFLAGS)

ROOTLIBS     = $(shell $(ROOTSYS)/bin/root-config --libs)

OBJS         = MyClass.o MyClass_dict.o

LIB          = libMyClass.so


all: lib

lib: $(OBJS)
	$(CXX) $(CXXFLAGS) -shared $(OBJS) $(ROOTLIBS) -o $(LIB)

clean:
	rm -rf $(OBJS) $(LIB) MyClass_dict.cc MyClass_dict.h


################################################################################
# $(OBJS)
################################################################################

MyClass.o: MyClass.h MyClass.cc
	$(CXX) $(CXXFLAGS) -c MyClass.cc -o MyClass.o

MyClass_dict.o:MyClass_dict.cc
	$(CXX) $(CXXFLAGS) -c MyClass_dict.cc -o MyClass_dict.o

MyClass_dict.cc: MyClass.h MyClass_linkdef.h
	rm -f MyClass_dict.cc MyClass_dict.h
	$(ROOTSYS)/bin/rootcint -f MyClass_dict.cc \
	-c MyClass.h MyClass_linkdef.h

and MyClass_linkdef.h looks as follows:

#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;

#pragma link C++ class MyClass;
#pragma link C++ class MyClass::MyInnerOne;
#pragma link C++ class MyClass::MyInnerTwo;
#endif // __CINT__

All of this works nicely until I introduce the std::vector<> member, then I get the following error:

 make
g++ -O3 -Wall -fPIC -I. -D_REENTRANT -pthread -I/usr/local/root/include -c MyClass.cc -o MyClass.o
rm -f MyClass_dict.cc MyClass_dict.h
/usr/local/root/bin/rootcint -f MyClass_dict.cc \
	-c MyClass.h MyClass_linkdef.h
g++ -O3 -Wall -fPIC -I. -D_REENTRANT -pthread -I/usr/local/root/include -c MyClass_dict.cc -o MyClass_dict.o
MyClass_dict.cc: In function 'int G__MyClass_dict_146_0_2(G__value*, const char*, G__param*, int)':
MyClass_dict.cc:283: error: 'MyInnerTwo' was not declared in this scope
MyClass_dict.cc:283: error: template argument 1 is invalid
MyClass_dict.cc:283: error: template argument 2 is invalid
MyClass_dict.cc:283: error: expected primary-expression before ')' token
MyClass_dict.cc:285: error: 'MyInnerTwo' was not declared in this scope
MyClass_dict.cc:285: error: template argument 1 is invalid
MyClass_dict.cc:285: error: template argument 2 is invalid
MyClass_dict.cc:285: error: expected primary-expression before ')' token
make: *** [MyClass_dict.o] Error 1

What am I doing wrong? Thanks!

Cheers, Philipp

Hi,

that’s a known issue with lookup of template arguments. Is there a chance to rephrase “std::vector twos_;” as “std::vectorMyClass::MyInnerTwo twos_;”? That should fix it.

Cheers, Axel.

Hi Axel,

thanks for the suggestion, that’s it! It needs to go into the argument list of the constructor as well though.

Cheers, Philipp