0

テンプレートクラスでピクルスに遭遇しました:

template <
          class N
         >
class Edge
{
  public:

    typedef std::shared_ptr<N> N_ptr;

    Edge
    (
      N_ptr node
     )
    {
       //...
    }

    template <class Archive>
    static Edge<N> * load_and_allocate( Archive & ar )
    {
      N_ptr node;
      ar( node );
      return new ::template Edge<N>( node );
    }
};

メソッド load_and_allocate は、デフォルトの空のコンストラクターを使用せずにオブジェクトを逆シリアル化するためにcerealに必要です。

load_and_allocate の戻り行の場合、コンパイラは次をスローします。

/usr/include/c++/4.7/bits/stl_construct.h: In instantiation of ‘void std::_Construct(_T1*, _Args&& ...) [with _T1 = Edge<Concept>; _Args = {}]’:
/usr/include/c++/4.7/bits/stl_uninitialized.h:497:3:   required from ‘static void std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = Edge<Concept>*; _Size = long unsigned int; bool _TrivialValueType = false]’
/usr/include/c++/4.7/bits/stl_uninitialized.h:545:7:   required from ‘void std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = Edge<Concept>*; _Size = long unsigned int]’
/usr/include/c++/4.7/bits/stl_uninitialized.h:607:7:   required from ‘void std::__uninitialized_default_n_a(_ForwardIterator, _Size, std::allocator<_Tp>&) [with _ForwardIterator = Edge<Concept>*; _Size = long unsigned int; _Tp = Edge<Concept>]’
/usr/include/c++/4.7/bits/vector.tcc:541:8:   required from ‘void std::vector<_Tp, _Alloc>::_M_default_append(std::vector<_Tp, _Alloc>::size_type) [with _Tp = Edge<Concept>; _Alloc = std::allocator<Edge<Concept> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int]’
/usr/include/c++/4.7/bits/stl_vector.h:647:4:   required from ‘void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = Edge<Concept>; _Alloc = std::allocator<Edge<Concept> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int]’
/usr/local/include/cereal/types/vector.hpp:83:5:   [ skipping 31 instantiation contexts ]
/usr/include/c++/4.7/bits/shared_ptr_base.h:525:8:   required from ‘std::__shared_count<_Lp>::__shared_count(std::_Sp_make_shared_tag, _Tp*, const _Alloc&, _Args&& ...) [with _Tp = SemanticGraph<Concept>; _Alloc = std::allocator<SemanticGraph<Concept> >; _Args = {const char (&)[16]}; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/4.7/bits/shared_ptr_base.h:997:35:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<SemanticGraph<Concept> >; _Args = {const char (&)[16]}; _Tp = SemanticGraph<Concept>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/4.7/bits/shared_ptr.h:317:64:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<SemanticGraph<Concept> >; _Args = {const char (&)[16]}; _Tp = SemanticGraph<Concept>]’
/usr/include/c++/4.7/bits/shared_ptr.h:599:39:   required from ‘std::shared_ptr<_Tp1> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = SemanticGraph<Concept>; _Alloc = std::allocator<SemanticGraph<Concept> >; _Args = {const char (&)[16]}]’
/usr/include/c++/4.7/bits/shared_ptr.h:615:42:   required from ‘std::shared_ptr<_Tp1> std::make_shared(_Args&& ...) [with _Tp = SemanticGraph<Concept>; _Args = {const char (&)[16]}]’
/home/alex/projects/Icarus/trunk/Api/Daemon/../ConnectionHandler/../../Processes/Controller/../../Datatypes/Domain/../../Handlers/SemanticNodeFactory/SemanticNodeFactory.hpp:34:82:   required from here
/usr/include/c++/4.7/bits/stl_construct.h:77:7: error: no matching function for call to ‘Edge<Concept>::Edge()’
/usr/include/c++/4.7/bits/stl_construct.h:77:7: note: candidates are:
candidate expects 1 argument, 0 provided
Edge<Relation>::Edge(const Edge<Relation>&)

メッセージは他のテンプレート (概念と関係) に対して繰り返されます。

同じことが起こります:

return new ::template Edge<N>( node );

return new Edge<N>::template Edge( node );

また

return new Edge<N>::template Edge<N>( node );

また

return new Edge<N>( node );

実際、ほとんどの人が修飾子について不満を述べており、最初の return ステートメントだけが修飾子に関するエラーを作成していません。

利用可能な唯一のコンストラクターを取得せず、渡したパラメーターを無視する理由を誰かが説明してもらえますか?

奇妙なことに、空のデフォルト パブリック コンストラクターを宣言すると、次のようになります。

Edge( ){ }

エラーなしでコンパイルされます。

4

1 に答える 1