Domanda

Sto cercando di capire se questo è un requisito cereale o no.

Continuo a ottenere errori che i costruttori di classe (quelli predefiniti) sono privati, che ho messo lì per un motivo.

Tuttavia, la linea di origine per l'errore, sembra essere, std :: make_shared, piuttosto che cereali, che richiede un costruttore predefinito, ma è già una classe di amici e dovrebbe quindi avere accesso ad esso.

/usr/include/c++/4.7/type_traits: In instantiation of ‘struct std::__is_default_constructible_impl<Concept>’:
/usr/include/c++/4.7/type_traits:116:12:   required from ‘struct std::__and_<std::__not_<std::is_void<Concept> >, std::__is_default_constructible_impl<Concept> >’
/usr/include/c++/4.7/type_traits:682:12:   required from ‘struct std::__is_default_constructible_atom<Concept>’
/usr/include/c++/4.7/type_traits:703:12:   required from ‘struct std::__is_default_constructible_safe<Concept, false>’
/usr/include/c++/4.7/type_traits:709:12:   required from ‘struct std::is_default_constructible<Concept>’
/usr/local/include/cereal/types/polymorphic.hpp:157:5:   required by substitution of ‘template<class Archive, class T> typename std::enable_if<((! std::is_default_constructible<T>::value) && (! has_load_and_allocate<T, Archive>())), bool>::type cereal::polymorphic_detail::serialize_wrapper(Archive&, std::shared_ptr<_Tp2>&, uint32_t) [with Archive = cereal::XMLInputArchive; T = Concept]’
/usr/local/include/cereal/types/polymorphic.hpp:253:5:   [ skipping 16 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/ConnectionHandler/../../Processes/Controller/../../Datatypes/Domain/../../Handlers/SemanticNodeFactory/SemanticNodeFactory.hpp:34:82:   required from here
/home/alex/projects/Icarus/trunk/Api/ConnectionHandler/../../Processes/Controller/../../Datatypes/Domain/../Episode/../State/../ConceptGraph/../Concept/Concept.hpp:27:5: error: ‘Concept::Concept()’ is private

Qualcuno può spiegarmi perché questo sta accadendo e, soprattutto, come potrebbe essere risolto, oltre a rendere pubblici quei costruttori?

MODIFICARE:

La linea di errore di origine è da:

concept_map  = std::make_shared<SemanticGraph<Concept>>( "concept_map.xml" );

Dove è il semavgrafo cTOR:

    SemanticGraph
    (
      const std::string filename
    )
    : 
      _fname ( filename )
    {
      std::ifstream input( _fname );
      if ( input.is_open() )
      {
       cereal::XMLInputArchive archive( input );
       archive( _nodes );
      }
    }
È stato utile?

Soluzione

C ++ utilizzato per non considerare il controllo dell'accesso quando si istanziano i modelli, tranne per produrre un errore se necessario. Il compilatore che stai usando usa ancora quelle regole. Per questo motivo, la tua classe non è considerata non-costruttibile. Invece, il controllo stesso è impossibile.

GCC 4.8 e superiore supportano questo. Un semplice programma dimostrativo che riesce con 4.8 e fallisce con 4.7 è:

#include <type_traits>

class S { S() {} };

int main() {
  return std::is_default_constructible<S>::value;
}

In 4.8, questo restituisce 0. In 4.7, questo produce un errore a tempo di compilazione.

Per risolvere questo problema, assicurati di non avere un costruttore predefinito, nemmeno privato. Puoi aggiungere un argomento fittizio al tuo costruttore e assicurarti di passare sempre quell'argomento fittizio.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top