gpt4 book ai didi

c++ - 无法将 Persistent 添加到 vector>

转载 作者:搜寻专家 更新时间:2023-10-31 01:37:06 24 4
gpt4 key购买 nike

我正在从 v8 3.x 迁移到 4.y,但我的某个头文件中定义的函数之一出现问题。

//JavascriptBase.h
namespace Company {
class Base {
protected:
void registerHandler(v8::Persistent<v8::Function>& func) {
user_functions_.push_back(func);
}
private:
std::vector<v8::Persistent<v8::Function>> user_functions_;
}
}

当我尝试编译时出现以下错误:

third-party2/v8/4.7.39/gcc-4.8.1-glibc-2.17-fb/281a9e6/include/v8.h:667:53: error: assigning to 'v8::Object *volatile' from incompatible type 'v8::Primitive *'
while (false) { *(static_cast<O* volatile*>(0)) = static_cast<Primitive*>(0); };
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
third-party2/v8/4.7.39/gcc-4.8.1-glibc-2.17-fb/281a9e6/include/v8.h:663:5: note: in instantiation of function template specialization 'v8::NonCopyablePersistentTraits<v8::Function>::Uncompilable<v8::Object>' requested here
Uncompilable<Object>();
^
third-party2/v8/4.7.39/gcc-4.8.1-glibc-2.17-fb/281a9e6/include/v8.h:7175:6: note: in instantiation of function template specialization 'v8::NonCopyablePersistentTraits<v8::Function>::Copy<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >' requested here
M::Copy(that, this);
^
third-party2/v8/4.7.39/gcc-4.8.1-glibc-2.17-fb/281a9e6/include/v8.h:729:5: note: in instantiation of function template specialization 'v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >::Copy<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >' requested here
Copy(that);
^
third-party2/libgcc/4.8.1/gcc-4.8.1-glibc-2.17-fb/8aac7fc/include/c++/4.8.1/ext/new_allocator.h:120:23: note: in instantiation of member function 'v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >::Persistent' requested here
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
^
third-party2/libgcc/4.8.1/gcc-4.8.1-glibc-2.17-fb/8aac7fc/include/c++/4.8.1/bits/alloc_traits.h:254:8: note: in instantiation of function template specialization '__gnu_cxx::new_allocator<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > >::construct<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >, const v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > &>' requested here
{ __a.construct(__p, std::forward<_Args>(__args)...); }
^
third-party2/libgcc/4.8.1/gcc-4.8.1-glibc-2.17-fb/8aac7fc/include/c++/4.8.1/bits/alloc_traits.h:393:4: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > > >::_S_construct<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >, const v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > &>' requested here
{ _S_construct(__a, __p, std::forward<_Args>(__args)...); }
^
third-party2/libgcc/4.8.1/gcc-4.8.1-glibc-2.17-fb/8aac7fc/include/c++/4.8.1/bits/stl_vector.h:905:21: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > > >::construct<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >, const v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > &>' requested here
_Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
^
./Company/JavaScriptBase.h:84:21: note: in instantiation of member function 'std::vector<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >, std::allocator<v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> > > >::push_back' requested here
user_functions_.push_back(func);
^
1 error generated.

我进行了一些谷歌搜索,发现 Persistent 对象不可分配,但我不确定如何处理这些信息。任何帮助将不胜感激。

最佳答案

如果它们不可分配,那么您(显然)不能分配它们。自 std::vector<>依赖于使用赋值运算符复制值,您的方法将行不通。

但是您可以存储指向它们的指针,因为复制任何东西的指针都是明确定义的。

关于c++ - 无法将 Persistent<Function> 添加到 vector<Persistent<Function>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34729216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com