0

I have a bison/flex C++ parser that has a class that I wrote as the return type for some of it's rules (defined in the parser file like %type <myClass> expr ). The class instance is then (usually) stored and printed out later. When the class instance is passed from one rule to another it loses all the values of it's members as if it's being instantiated but not fully copied. I have an = operator and a copy constructor defined for the class. I've also tried manually copying in the members like so:

expr: //Returns myClass
    atomicexpr  { //Also returns myClass
       $$ = driver.returnClass($1)
       $$.member1 = driver.returnClass($1).member1
       $$.member2 = driver.returnClass($1).member2
    }

Note that I am using variants instead of unions as demonstrated in the C++ example in the bison manual.

What do I need to do to get the class instantiated properly?

ZackG
  • 177
  • 3
  • 3
  • 9
  • Sounds like the object is being sliced. http://stackoverflow.com/q/274626/14065 I think you need to pass pointers as the return value. – Martin York Feb 23 '16 at 05:14
  • Hmm. In theory they're all the same type (not derived) so they wouldn't be sliced. But I changed it to passing pointers with the same result. – ZackG Feb 23 '16 at 05:36

0 Answers0