c++ - std::unique_ptr<Mesh>::unique_ptr(__gnu_cxx::__alloc_traits<std::allocator<Mesh> >::value_type&)’ -
i'm using c++ std11 , i've following code
#include "renderengine.h" #include "cam.h" #include "vec3d.h" #include "mesh.h" #include "model.h" #include <vector> #include <memory> struct option { int imagewidth, imageheight; }; int main() { cam* cam = new cam(vec3d(0.0, 0.0, 250.0), vec3d(0.0, 0.0, -1.0), 90, 1); //cam* cam = new cam(); option option; option.imagewidth = 1920; option.imageheight = 1080; //option.imagewidth = 1280; //option.imageheight = 900; model mymodel; mymodel.loadmodel("/models/arm.obj"); std::vector<std::unique_ptr<mesh>> objects; std::unique_ptr<mesh> mymesh( mymodel.meshes[0] ); objects.push_back(std::move(mymesh)); renderengine* render = new renderengine(*cam, option.imagewidth, option.imageheight); render->getimage(objects); delete cam; delete render; return 0; }
with class model
contain std::vector<mesh> meshes
;
when compile code i'm following error:
andreaolivieri@andreaolivieri-aspire-v3-571:~/documenti/c++/progetti_pog/002_beta$ make g++ -wall -c -g -std=c++11 testrender.cpp -o obj/testrender.o -llib testrender.cpp: in function ‘int main()’: testrender.cpp:27:50: error: no matching function call ‘std::unique_ptr<mesh>::unique_ptr(__gnu_cxx::__alloc_traits<std::allocator<mesh> >::value_type&)’ std::unique_ptr<mesh> mymesh( mymodel.meshes[0] ); ^ testrender.cpp:27:50: note: candidates are: in file included /usr/include/c++/4.8/memory:81:0, renderengine.h:13, testrender.cpp:1: /usr/include/c++/4.8/bits/unique_ptr.h:176:2: note: template<class _up, class> std::unique_ptr<_tp, _dp>::unique_ptr(std::auto_ptr<_up>&&) unique_ptr(auto_ptr<_up>&& __u) noexcept; ^ /usr/include/c++/4.8/bits/unique_ptr.h:176:2: note: template argument deduction/substitution failed: testrender.cpp:27:50: note: ‘__gnu_cxx::__alloc_traits<std::allocator<mesh> >::value_type {aka mesh}’ not derived ‘std::auto_ptr<_up>’ std::unique_ptr<mesh> mymesh( mymodel.meshes[0] ); ^ in file included /usr/include/c++/4.8/memory:81:0, renderengine.h:13, testrender.cpp:1: /usr/include/c++/4.8/bits/unique_ptr.h:169:2: note: template<class _up, class _ep, class> std::unique_ptr<_tp, _dp>::unique_ptr(std::unique_ptr<_up, _ep>&&) unique_ptr(unique_ptr<_up, _ep>&& __u) noexcept ^ /usr/include/c++/4.8/bits/unique_ptr.h:169:2: note: template argument deduction/substitution failed: testrender.cpp:27:50: note: ‘__gnu_cxx::__alloc_traits<std::allocator<mesh> >::value_type {aka mesh}’ not derived ‘std::unique_ptr<_tp, _dp>’ std::unique_ptr<mesh> mymesh( mymodel.meshes[0] ); ^ in file included /usr/include/c++/4.8/memory:81:0, renderengine.h:13, testrender.cpp:1: /usr/include/c++/4.8/bits/unique_ptr.h:160:7: note: std::unique_ptr<_tp, _dp>::unique_ptr(std::unique_ptr<_tp, _dp>&&) [with _tp = mesh; _dp = std::default_delete<mesh>] unique_ptr(unique_ptr&& __u) noexcept ^ /usr/include/c++/4.8/bits/unique_ptr.h:160:7: note: no known conversion argument 1 ‘__gnu_cxx::__alloc_traits<std::allocator<mesh> >::value_type {aka mesh}’ ‘std::unique_ptr<mesh>&&’ /usr/include/c++/4.8/bits/unique_ptr.h:157:17: note: constexpr std::unique_ptr<_tp, _dp>::unique_ptr(std::nullptr_t) [with _tp = mesh; _dp = std::default_delete<mesh>; std::nullptr_t = std::nullptr_t] constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } ^ /usr/include/c++/4.8/bits/unique_ptr.h:157:17: note: no known conversion argument 1 ‘__gnu_cxx::__alloc_traits<std::allocator<mesh> >::value_type {aka mesh}’ ‘std::nullptr_t’ /usr/include/c++/4.8/bits/unique_ptr.h:151:7: note: std::unique_ptr<_tp, _dp>::unique_ptr(std::unique_ptr<_tp, _dp>::pointer, typename std::remove_reference<_to>::type&&) [with _tp = mesh; _dp = std::default_delete<mesh>; std::unique_ptr<_tp, _dp>::pointer = mesh*; typename std::remove_reference<_to>::type = std::default_delete<mesh>] unique_ptr(pointer __p, ^ /usr/include/c++/4.8/bits/unique_ptr.h:151:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/4.8/bits/unique_ptr.h:146:7: note: std::unique_ptr<_tp, _dp>::unique_ptr(std::unique_ptr<_tp, _dp>::pointer, typename std::conditional<std::is_reference<_dp>::value, _dp, const _dp&>::type) [with _tp = mesh; _dp = std::default_delete<mesh>; std::unique_ptr<_tp, _dp>::pointer = mesh*; typename std::conditional<std::is_reference<_dp>::value, _dp, const _dp&>::type = const std::default_delete<mesh>&] unique_ptr(pointer __p, ^ /usr/include/c++/4.8/bits/unique_ptr.h:146:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/4.8/bits/unique_ptr.h:141:7: note: std::unique_ptr<_tp, _dp>::unique_ptr(std::unique_ptr<_tp, _dp>::pointer) [with _tp = mesh; _dp = std::default_delete<mesh>; std::unique_ptr<_tp, _dp>::pointer = mesh*] unique_ptr(pointer __p) noexcept ^ /usr/include/c++/4.8/bits/unique_ptr.h:141:7: note: no known conversion argument 1 ‘__gnu_cxx::__alloc_traits<std::allocator<mesh> >::value_type {aka mesh}’ ‘std::unique_ptr<mesh>::pointer {aka mesh*}’ /usr/include/c++/4.8/bits/unique_ptr.h:135:17: note: constexpr std::unique_ptr<_tp, _dp>::unique_ptr() [with _tp = mesh; _dp = std::default_delete<mesh>] constexpr unique_ptr() noexcept ^ /usr/include/c++/4.8/bits/unique_ptr.h:135:17: note: candidate expects 0 arguments, 1 provided make: *** [obj/testrender.o] errore 1
please don't understand where's error, i've vector of mesh
, use operator[]
give me mesh
, creat unique_ptr<mesh>
thanks.
ps. class:
#ifndef _model_h #define _model_h #include "mesh.h" #include <vector> #include <assimp/importer.hpp> #include <assimp/scene.h> #include <assimp/postprocess.h> class model { public: std::vector<mesh> meshes; std::string directory; void loadmodel(std::string path); void processnode(ainode* node, const aiscene* scene); mesh processmesh(aimesh* mesh, const aiscene* scene); }; #endif #ifndef _mesh_h #define _mesh_h #include "vec3d.h" #include "ray.h" #include <vector> class mesh { protected: unsigned int numvertices, numfaces; std::vector<unsigned int> vertexindex; std::vector<vec3d> verts; std::vector<vec3d> vertexnormals; vec3d cl; public: mesh(unsigned int &_numvertices, unsigned int &_numfaces, std::vector<unsigned int> &_vertexindex, std::vector<vec3d> &_verts, std::vector<vec3d> &_vertexnormals); bool intersect(ray &r, double &t, double &u, double &v); inline const vec3d getcl(){ return cl; } }; #endif
use function std::make_unique
instead of constructor (line 27):
std::unique_ptr<mesh> mymesh = std::make_unique (mymodel.meshes[0]);
include <memory>
use std::make_unique
!
Comments
Post a Comment