Flatbuffer compilation error in saving internal buffer pointer as shared reference.

155 visningar
Hoppa till det första olästa meddelandet

Gaurav Jain

oläst,
28 apr. 2016 03:11:342016-04-28
till FlatBuffers
I have written a following piece of code, for generated a Flatbuffer builder object and then I assign it to some global shared pointer reference.
For this, I first call ReleaseBufferPointer() to get a unique pointer and then generate a shared pointer from this unique pointer.
Here is the code snippet for this

// some global shared ptr ref:
shared_ptr<SomeBufferBuilder> buffer_ref;

...


{ FlatBufferBuilder fbb;                                                                   // Create flat buffer builder object
  SomeBufferBuilder buffer_builder(fbb);
  buffer_builder.add_params(...);
  auto buffer_offset = buffer_builder.Finish();
  fbb.Finish(buffer_offset);                                                            // Finished flatbuffer builder object

  shared_ptr<uint8_t> buffer_shptr(fbb.ReleaseBufferPointer());     // Release owner ship for buffer pointer by flat buffer builder
  buffer_ref = dynamic_pointer_cast<SomeBufferBuilder>(buffer_shptr);    // since target is of type "SomeBufferBuilder" we need to dynamic cast the buffer pointer.
}



I am getting following error during compilation, any leads regarding the same Or is there a better way to do this task?


/opt/rh/devtoolset-3/root/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../include/c++/4.9.2/bits/shared_ptr.h:455:22: error: 'unsigned char' is not a class
      if (_Tp* __p = dynamic_cast<_Tp*>(__r.get()))
                     ^                  ~~~~~~~~~
/home/sample.cc:482:34: note: in instantiation of function template specialization 'std::dynamic_pointer_cast< SomeBufferBuilder, unsigned char>' requested here
   buffer_ref = dynamic_pointer_cast<SomeBufferBuilder>(buffer_shptr);
             ^
1 error generated.

Gaurav Jain

oläst,
3 maj 2016 12:44:262016-05-03
till FlatBuffers
Still awaiting for any response ..

Wouter van Oortmerssen

oläst,
20 maj 2016 18:22:162016-05-20
till Gaurav Jain, FlatBuffers
You're initializing a `shared_ptr` with a `unique_ptr` (which is what is returned `ReleaseBufferPointer`).. which I didn't even know is possible. But the code might be easier if you just kept it a `unique_ptr`.

Also, I'm not sure why you're trying to cast to `SomeBufferBuilder`. This type is purely used during construction, and is not the type of the buffer. The buffer type is a uint8_t *, and C++ doesn't like you casting that to a class. I suggest you keep that type for buffer_ref.

--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden