%class Variable
%language c++
%namespace Data
%{
  //C++ code here
  //it will be include before class declaration
#include &lt;iostream&gt;
%}

%var		std::string     name("")
%var		int             val(0)
%var_vector     int             subvars

%{
  //C++ Code here
  //it will be include in class declaration
  public:
    void print(std::ostream& s) const
      {
        s &lt;&lt; _name &lt;&lt; ' ' &lt;&lt; _val &lt;&lt; std::endl;
        for (unsigned int i = 0; i &lt; _subvars.size(); i++)
          s &lt;&lt; _subvars[i] &lt;&lt; ' ';
        s &lt;&lt; std::endl;
      }
%}

%%

//Code outside classe declaration
inline std::ostream& operator&lt;&lt;(std::ostream& s, const Variable& v)
{
  v.print(s);
  return s;
}
